https://github.com/microsoftgraph/msgraph-sdk-ruby#usage-example
require 'adal'
require 'microsoft_graph'
# authenticate using ADAL
username = '
[email protected]'
password = 'xxxxxxxxxxxx'
client_id = 'xxxxx-xxxx-xxx-xxxxxx-xxxxxxx'
client_secret = 'xxxXXXxxXXXxxxXXXxxXXXXXXXXxxxxxx='
tenant = 'tenant.onmicrosoft.com'
user_cred = ADAL::UserCredential.new(username, password)
client_cred = ADAL::ClientCredential.new(client_id, client_secret)
context = ADAL::AuthenticationContext.new(ADAL::Authority::WORLD_WIDE_AUTHORITY, tenant)
resource = "https://graph.microsoft.com"
tokens = context.acquire_token_for_user(resource, client_cred, user_cred)
# add the access token to the request header
callback = Proc.new { |r| r.headers["Authorization"] = "Bearer #{tokens.access_token}" }
graph = MicrosoftGraph.new(base_url: "https://graph.microsoft.com/v1.0",
cached_metadata_file: File.join(MicrosoftGraph::CACHED_METADATA_DIRECTORY, "metadata_v1.0.xml"),
api_version: '1.6', # Optional
&callback
)
me = graph.me # get the current user
puts "Hello, I am #{me.display_name}."
me.direct_reports.each do |person|
puts "How's it going, #{person.display_name}?"
end
͜ͷαϯϓϧΛಈ͔͢ͱ…