$30 off During Our Annual Pro Sale. View Details »

Microsoft Graph API Client and OpenAPI

jinroq
October 01, 2019

Microsoft Graph API Client and OpenAPI

jinroq

October 01, 2019
Tweet

More Decks by jinroq

Other Decks in Technology

Transcript

  1. Microsoft Graph • Ϣʔβʔ৘ใΛศརʹѻ͑ΔαʔϏε • Azure AD • Office 365

    αʔϏε • OneDrive • ͳͲͳͲ • G Suite ͱΑ͘ൺֱ͞ΕΔ https://docs.microsoft.com/en-us/graph/?view=graph-rest-1.0
  2. platform URL commits Android https://github.com/microsoftgraph/msgraph-sdk-android 259 Angular https://github.com/microsoftgraph/msgraph-sdk-javascript 469 ASP

    .NET https://www.nuget.org/packages/Microsoft.Graph — iOS https://github.com/microsoftgraph/msgraph-sdk-objc 110 Java https://github.com/microsoftgraph/msgraph-sdk-java 445 JavaScript https://github.com/microsoftgraph/msgraph-sdk-javascript 469 Node.js https://github.com/microsoftgraph/msgraph-sdk-javascript 469 PHP https://github.com/microsoftgraph/msgraph-sdk-php 227 Ruby https://github.com/microsoftgraph/msgraph-sdk-ruby 34 UWP https://www.nuget.org/packages/Microsoft.Graph — Xamarin https://www.nuget.org/packages/Microsoft.Graph — SDK ͷ։ൃঢ়گ
  3. platform URL commits Android https://github.com/microsoftgraph/msgraph-sdk-android 259 Angular https://github.com/microsoftgraph/msgraph-sdk-javascript 469 ASP

    .NET https://www.nuget.org/packages/Microsoft.Graph — iOS https://github.com/microsoftgraph/msgraph-sdk-objc 110 Java https://github.com/microsoftgraph/msgraph-sdk-java 445 JavaScript https://github.com/microsoftgraph/msgraph-sdk-javascript 469 Node.js https://github.com/microsoftgraph/msgraph-sdk-javascript 469 PHP https://github.com/microsoftgraph/msgraph-sdk-php 227 Ruby https://github.com/microsoftgraph/msgraph-sdk-ruby 34 UWP https://www.nuget.org/packages/Microsoft.Graph — Xamarin https://www.nuget.org/packages/Microsoft.Graph — MS ϓϥοτϑΥʔϜ͸ NuGet ͔Βఏڙ
  4. platform URL commits Android https://github.com/microsoftgraph/msgraph-sdk-android 259 Angular https://github.com/microsoftgraph/msgraph-sdk-javascript 469 ASP

    .NET https://www.nuget.org/packages/Microsoft.Graph — iOS https://github.com/microsoftgraph/msgraph-sdk-objc 110 Java https://github.com/microsoftgraph/msgraph-sdk-java 445 JavaScript https://github.com/microsoftgraph/msgraph-sdk-javascript 469 Node.js https://github.com/microsoftgraph/msgraph-sdk-javascript 469 PHP https://github.com/microsoftgraph/msgraph-sdk-php 227 Ruby https://github.com/microsoftgraph/msgraph-sdk-ruby 34 UWP https://www.nuget.org/packages/Microsoft.Graph — Xamarin https://www.nuget.org/packages/Microsoft.Graph — JS ܥ͸ඃ͍ͬͯΔ
  5. platform URL commits Android https://github.com/microsoftgraph/msgraph-sdk-android 259 Angular https://github.com/microsoftgraph/msgraph-sdk-javascript 469 ASP

    .NET https://www.nuget.org/packages/Microsoft.Graph — iOS https://github.com/microsoftgraph/msgraph-sdk-objc 110 Java https://github.com/microsoftgraph/msgraph-sdk-java 445 JavaScript https://github.com/microsoftgraph/msgraph-sdk-javascript 469 Node.js https://github.com/microsoftgraph/msgraph-sdk-javascript 469 PHP https://github.com/microsoftgraph/msgraph-sdk-php 227 Ruby https://github.com/microsoftgraph/msgraph-sdk-ruby 34 UWP https://www.nuget.org/packages/Microsoft.Graph — Xamarin https://www.nuget.org/packages/Microsoft.Graph — Ͱ΋ຊ౰ʹண໨͢΂͖͸͜͜ʂ
  6. ࢀߟ·Ͱʹ… • 2010/10/14 ʹ v. 0.1.0 ެ։ • ݱࡏ v.

    0.31.0 • ৽ػೳͷ௥Ճ͸ͳ͘ɺॏେͳ όάͱηΩϡϦςΟύονͷ Έ https://rubygems.org/gems/google-api-client
  7. 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
  8. 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 ͜ͷαϯϓϧΛಈ͔͢ͱ…
  9. 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 <= ͜͜ͰίέΔ
  10. Microsoft Graph SDK for Ruby ͷ໰୊఺ • ʮRuby ରԠʯͱᨳ͍ͬͯΔ͕ SDK

    ͸࣮͸ preview ൛ • ϝϯςφϯε͞Ε͍ͯΔͱ͸౸ఈࢥ͑ͳ͍ • GitHub Overview ʹهࡌ͞Ε͍ͯΔαϯϓϧͰ͑͞·ͱ΋ʹಈ͔ͳ͍ • υΩϡϝϯτ͕ͳ͍ͷͰ࢖͍ํ͕શ͘෼͔Βͳ͍
  11. ࣗ࡞ͷ೉ؔ • ΤϯυϙΠϯτ਺͕๲େ • طଘͷ࣮૷͕೉ղ • OData Protocol • Microsoft

    ͕ 2007 ೥ʹఏএʢݱࡏ ver. 4.01ʣ • RESTful API ΛΑΓ؆୯ʹѻ͑ΔΑ͏ʹߟ͑ΒΕͨ
 Φʔϓϯϓϩτίϧ • https://www.odata.org/documentation/
  12. ࣗ࡞ͷ೉ؔ • ΤϯυϙΠϯτ਺͕๲େ • طଘͷ࣮૷͕೉ղ • OData Protocol • Microsoft

    ͕ 2007 ೥ʹఏএʢݱࡏ ver. 4.01ʣ • RESTful API ΛΑΓ؆୯ʹѻ͑ΔΑ͏ʹߟ͑ΒΕͨ
 Φʔϓϯϓϩτίϧ • https://www.odata.org/documentation/
  13. ࣗ࡞ͷ೉ؔ • ΤϯυϙΠϯτ਺͕๲େ • طଘΛ౿ऻ͢Δͷ͕ࠔ೉ • OData Protocol • Microsoft

    ͕ 2007 ೥ʹఏএʢݱࡏ ver. 4.01ʣ • RESTful API ΛΑΓ؆୯ʹѻ͑ΔΑ͏ʹߟ͑ΒΕͨ
 Φʔϓϯϓϩτίϧ • https://www.odata.org/documentation/ ΋ͬͱָʹࣗ࡞Ͱ͖Δ
 ํ๏͸ͳ͍ͩΖ͏͔ʁ
  14. OpenAPI • ϓϩάϥϛϯάݴޠʹґଘ͠ͳ͍ RESTful API ΠϯλϑΣʔεͷఆٛ • ࢓༷ͷݺশ͸ OpenAPI Specification

    • https://github.com/OAI/OpenAPI-Specification • ݱࡏ v. 3.0.2 • چ Swagger specification • ࢀߟɿ https://speakerdeck.com/akihito_nakano/gunmaweb34
  15. OpenAPI Generator • OpenAPI Specification ʹଇͬͯ YAML/JSON ϑΝΠϧΛ࡞੒͢Ε͹
 ͦΕΛجʹ API

    Client Λੜ੒ͯ͘͠ΕΔπʔϧ • https://github.com/OpenAPITools/openapi-generator • ࢀߟɿ https://rubykaigi.org/2019/presentations/ota42y.html#apr18
  16. ·ͱΊ • Microsoft Graph • αʔϏεͱͯ͠͸ศར • υΩϡϝϯτ΍ SDK ΋׬උʢ˞

    Ruby Λআ͘ʣ • OpenAPI • ϓϩάϥϛϯάݴޠʹґଘ͠ͳ͍ RESTful API ΠϯλϑΣʔεͷఆٛ • OpenAPI Generator Λ্ख͘׆༻Ͱ͖Ε͹ Microsoft Graph SDK Λ
 ࠶ൃ໌Ͱ͖ͦ͏ • ࣗ࡞͢Δಓ͸ͲͷಓΛબΜͰ΋Ἒͷಓ • Microsoft Graph SDK for Ruby ΛͪΌΜͱϝϯςφϯεͯ͘͠ΕΕ͹ສࣄղܾ͢Δ…