if (FALSE) {
# start a new Graph session
gr <- ms_graph$new(tenant="myaadtenant.onmicrosoft.com")
# authenticate with credentials in a file
gr <- ms_graph$new(config_file="creds.json")
# authenticate with device code
gr <- ms_graph$new(tenant="myaadtenant.onmicrosoft.com", app="app_id", auth_type="device_code")
# retrieve an app registration
gr$get_app(app_id="myappid")
# create a new app and associated service principal, set password duration to 10 years
app <- gr$create_app("mynewapp", password_duration=10)
# delete the app
gr$delete_app(app_id=app$properties$appId)
# ... but better to call the object's delete method directly
app$delete()
# create an app with authentication via a certificate
cert <- readLines("mycert.cer")
gr$create_app("mycertapp", password=FALSE, certificate=cert)
# retrieving your own user details (assuming interactive authentication)
gr$get_user()
# retrieving another user's details
gr$get_user("username@myaadtenant.onmicrosoft.com")
gr$get_user(email="firstname.lastname@mycompany.com")
gr$get_user(name="Hong Ooi")
# get an AAD object (a group)
id <- gr$get_user()$list_group_memberships()[1]
gr$get_aad_object(id)
# list the users in the tenant
gr$list_users()
# list (guest) users with a 'gmail.com' email address
gr$list_users(filter="endsWith(mail,'gmail.com')")
# list Microsoft 365 groups
gr$list_groups(filter="groupTypes/any(c:c eq 'Unified')")
}
Run the code above in your browser using DataLab