{"id":2002,"date":"2018-11-08T11:00:50","date_gmt":"2018-11-08T11:00:50","guid":{"rendered":"https:\/\/developer.microsoft.com\/en-us\/office\/blogs\/?p=2002"},"modified":"2018-11-08T11:00:50","modified_gmt":"2018-11-08T11:00:50","slug":"30daysmsgraph-day-8-authentication-roadmap-and-access-tokens","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/30daysmsgraph-day-8-authentication-roadmap-and-access-tokens\/","title":{"rendered":"30DaysMSGraph \u2013 Day 8 \u2013 Authentication roadmap and access tokens"},"content":{"rendered":"<p><a href=\"https:\/\/aka.ms\/30DaysMSGraph\">List of all posts in the #30DaysMSGraph series<\/a><\/p>\n<p>In <a href=\"https:\/\/developer.microsoft.com\/en-us\/graph\/blogs\/30daysmsgraph-day-7-paging-and-nextlink\">Day 7<\/a> we discussed paging results for Microsoft Graph requests.\u00a0 Today we&#8217;ll look at the current and future states of authenticating to Microsoft Graph, specifically obtaining access tokens.<img decoding=\"async\" class=\"aligncenter wp-image-2041 \" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/30DaysMSGraph_Day8_Source.png\" alt=\"\" width=\"593\" height=\"309\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/30DaysMSGraph_Day8_Source.png 977w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/30DaysMSGraph_Day8_Source-300x156.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/30DaysMSGraph_Day8_Source-768x399.png 768w\" sizes=\"(max-width: 593px) 100vw, 593px\" \/>Any calls made to Microsoft Graph need to be properly authenticated by including an access token.\u00a0 In the case of Microsoft Graph an access token is a base 64 encoded JSON web token (JWT) which must be issued by Azure Active Directory (Azure AD).<\/p>\n<p>There are 2 primary authentication flows against Azure Active Directory:<\/p>\n<ol>\n<li>On behalf of user\n<ol>\n<li>Also called delegated or app + user<\/li>\n<\/ol>\n<\/li>\n<li>Application\n<ol>\n<li>Also called app-only<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>Depending on which authentication flow you build into your application the high-level steps will be as follows:<\/p>\n<ol>\n<li>Register application in Azure AD<\/li>\n<li>Configure \/ grant permissions<\/li>\n<li>Get access token<\/li>\n<li>Use access token to call Microsoft Graph<\/li>\n<\/ol>\n<p>We&#8217;ll cover each of these steps in greater detail in later posts.<\/p>\n<p>Knowing that we need to obtain an access token, let&#8217;s discuss the current and future states of authenticating to Microsoft Graph.\u00a0 Keep in mind there are a few elements that are currently in <a href=\"https:\/\/github.com\/AzureAD\/microsoft-authentication-library-for-js#important-note-about-the-msal-preview\">production supported preview<\/a>.<\/p>\n<h3>Current state<\/h3>\n<p>Currently, authenticating against Microsoft Graph involves a few decisions as there are multiple portals to register an application, multiple client SDKs, and multiple Azure AD endpoints.\u00a0 Knowing your target audience is a key decision point as it influences which components you can or can&#8217;t use.\u00a0 MSAL and the Azure AD v2 endpoint are the go-forward direction (see Future state below) and as such we recommend you start there.\u00a0 ADAL and the v1 endpoints currently support a limited number of authentication scenarios that aren&#8217;t yet in MSAL \/ Azure AD v2 endpoint but those differences are expected to be addressed soon\u00a0.\u00a0 Please see the article for <a href=\"https:\/\/docs.microsoft.com\/azure\/active-directory\/develop\/active-directory-v2-limitations\">Comparing the Azure AD v2.0 endpoint with the v1.0 endpoint<\/a> link in the appendix for the most up-to-date information on deciding between v1 or v2.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-2042\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/Day08-AccessToken4-1024x431.png\" alt=\"\" width=\"800\" height=\"337\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/Day08-AccessToken4-1024x431.png 1024w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/Day08-AccessToken4-300x126.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/Day08-AccessToken4-768x323.png 768w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/Day08-AccessToken4.png 1241w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<h3>Future state<\/h3>\n<p>The future state of authenticating to Microsoft Graph is targeting the following diagram.\u00a0 In this diagram notice that the Azure AD v2 endpoint can issue v1 or v2 tokens.\u00a0 Additionally, the Azure Portal is the sole location for registering applications.\u00a0 \u00a0 Overall the future state simplifies authenticating to Microsoft Graph by reducing the number of decision points and providing support for the broadest set of requirements.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-2043\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/Day08-AccessToken5-1024x440.png\" alt=\"\" width=\"800\" height=\"344\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/Day08-AccessToken5-1024x440.png 1024w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/Day08-AccessToken5-300x129.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/Day08-AccessToken5-768x330.png 768w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/Day08-AccessToken5.png 1262w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<h3><\/h3>\n<p>We&#8217;ll cover the actual steps to obtain an access token over the next few posts.\u00a0 For the time being let&#8217;s inspect an access token such as the below sample (sensitive information obscured):<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-2044 size-large\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/Day08-AccessToken2b-e1541640619342-1024x284.png\" alt=\"\" width=\"1024\" height=\"284\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/Day08-AccessToken2b-e1541640619342-1024x284.png 1024w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/Day08-AccessToken2b-e1541640619342-300x83.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/Day08-AccessToken2b-e1541640619342-768x213.png 768w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/Day08-AccessToken2b-e1541640619342.png 1150w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p><em>Note: An Azure AD access token is a Bearer token meaning any person or application that has possession of it can use it to make calls against Microsoft Graph with the consented permissions.\u00a0 As such you must ensure secure transmission and \/ or storage of them to prevent unintended use.<\/em><\/p>\n<p>At first glance the format of these access tokens may appear unreadable, but you can decode them using various tools.\u00a0 The Azure AD team has provided the website <a href=\"http:\/\/jwt.ms\/\">http:\/\/jwt.ms<\/a> as one example.\u00a0 The following is an example of the output from a sample access token.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-2045\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/Day08-AccessToken3-1024x591.png\" alt=\"\" width=\"800\" height=\"462\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/Day08-AccessToken3-1024x591.png 1024w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/Day08-AccessToken3-300x173.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/Day08-AccessToken3-768x443.png 768w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/11\/Day08-AccessToken3.png 1150w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>Use the <strong>Claims<\/strong> tab after decoding an access token for additional information on each of the claims presented.\u00a0 This can be very helpful for troubleshooting an issue where an access token was generated with the incorrect scopes \/ roles, was issued for the wrong resource \/ audience, and more.\u00a0 Find additional information on the access token schema available in the\u00a0<a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/active-directory\/develop\/access-tokens\">Azure Active Directory Access Tokens<\/a>\u00a0resource.<\/p>\n<p>&nbsp;<\/p>\n<h2>Try It Out<\/h2>\n<p>Navigate to the documentation for Azure AD Access Tokens.\u00a0 Decode the v1 and v2 sample tokens using <a href=\"http:\/\/jwt.ms\">http:\/\/jwt.ms<\/a>.\u00a0 Inspect the claims used for each<\/p>\n<p><a href=\"https:\/\/github.com\/microsoftgraph\/30DaysMSGraph-TryItOut\/blob\/master\/Day08-AccessTokens.md\">Day 8 repo link<\/a><\/p>\n<ol>\n<li>V1 sample token\n<ul>\n<li>eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Imk2bEdrM0ZaenhSY1ViMkMzbkVRN3N5SEpsWSIsImtpZCI6Imk2bEdrM0ZaenhSY1ViMkMzbkVRN3N5SEpsWSJ9.eyJhdWQiOiJlZjFkYTlkNC1mZjc3LTRjM2UtYTAwNS04NDBjM2Y4MzA3NDUiLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC9mYTE1ZDY5Mi1lOWM3LTQ0NjAtYTc0My0yOWYyOTUyMjIyOS8iLCJpYXQiOjE1MzcyMzMxMDYsIm5iZiI6MTUzNzIzMzEwNiwiZXhwIjoxNTM3MjM3MDA2LCJhY3IiOiIxIiwiYWlvIjoiQVhRQWkvOElBQUFBRm0rRS9RVEcrZ0ZuVnhMaldkdzhLKzYxQUdyU091TU1GNmViYU1qN1hP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U2LTQ4NDMtOWZmNC1lNjZhMzliYjEyZTMiLCJpc3MiOiJodHRwczovL2xvZ2luLm1pY3Jvc29mdG9ubGluZS5jb20vNzJmOTg4YmYtODZmMS00MWFmLTkxYWItMmQ3Y2QwMTFkYjQ3L3YyLjAiLCJpYXQiOjE1MzcyMzEwNDgsIm5iZiI6MTUzNzIzMTA0OCwiZXhwIjoxNTM3MjM0OTQ4LCJhaW8iOiJBWFFBaS84SUFBQUF0QWFaTG8zQ2hNaWY2S09udHRSQjdlQnE0L0RjY1F6amNKR3hQWXkvQzNqRGFOR3hYZDZ3TklJVkdSZ2hOUm53SjFsT2NBbk5aY2p2a295ckZ4Q3R0djMzMTQwUmlvT0ZKNGJDQ0dWdW9DYWcxdU9UVDIyMjIyZ0h3TFBZUS91Zjc5UVgrMEtJaWpkcm1wNjlSY3R6bVE9PSIsImF6cCI6IjZlNzQxNzJiLWJlNTYtNDg0My05ZmY0LWU2NmEzOWJiMTJlMyIsImF6cGFjciI6IjAiLCJuYW1lIjoiQWJlIExpbmNvbG4iLCJvaWQiOiI2OTAyMjJiZS1mZjFhLTRkNTYtYWJkMS03ZTRmN2QzOGU0NzQiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJhYmVsaUBtaWNyb3NvZnQuY29tIiwicmgiOiJJIiwic2NwIjoiYWNjZXNzX2FzX3VzZXIiLCJzdWIiOiJIS1pwZmFIeVdhZGVPb3VZbGl0anJJLUtmZlRtMjIyWDVyclYzeERxZktRIiwidGlkIjoiNzJmOTg4YmYtODZmMS00MWFmLTkxYWItMmQ3Y2QwMTFkYjQ3IiwidXRpIjoiZnFpQnFYTFBqMGVRYTgyUy1JWUZBQSIsInZlciI6IjIuMCJ9.pj4N-w_3Us9DrBLfpCt<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>Join us tomorrow as we register Azure AD applications with the V2 endpoint in <a href=\"https:\/\/developer.microsoft.com\/en-us\/graph\/blogs\/30daysmsgraph-day-9-azure-ad-applications-on-v2-endpoint\">Day 9<\/a>.<\/p>\n<h2>Appendix<\/h2>\n<ul>\n<li><a href=\"https:\/\/developer.microsoft.com\/en-us\/graph\/docs\/concepts\/auth_overview\">Get access tokens to call Microsoft Graph<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/active-directory\/develop\/access-tokens\">Azure Active Directory Access Tokens<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/azure\/active-directory\/develop\/active-directory-v2-limitations\">Comparing the Azure AD v2.0 endpoint with the v1.0 endpoint<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/active-directory\/develop\/quickstart-register-app\">Quickstart: Register an application with the Microsoft identity platform (Preview)<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In Day 7 we discussed paging results for Microsoft Graph requests.\u00a0 Today we&#8217;ll look at the current and future states of authenticating to Microsoft Graph, specifically obtaining access tokens.<\/p>\n","protected":false},"author":73055,"featured_media":25159,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[3],"tags":[84],"class_list":["post-2002","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microsoft-graph","tag-30daysmsgraph"],"acf":[],"blog_post_summary":"<p>In Day 7 we discussed paging results for Microsoft Graph requests.\u00a0 Today we&#8217;ll look at the current and future states of authenticating to Microsoft Graph, specifically obtaining access tokens.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/2002","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/users\/73055"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/comments?post=2002"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/2002\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media\/25159"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media?parent=2002"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/categories?post=2002"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/tags?post=2002"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}