You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/active-directory/develop/v2-protocols-oidc.md
+64-33Lines changed: 64 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,25 +14,45 @@ ms.topic: reference
14
14
15
15
# OpenID Connect on the Microsoft identity platform
16
16
17
-
OpenID Connect (OIDC) extends the OAuth 2.0 authorization protocol for use also as an authentication protocol. You can use OIDC to enable single sign-on (SSO) between your OAuth-enabled applications.
17
+
OpenID Connect (OIDC) extends the OAuth 2.0 authorization protocol for use also as an authentication protocol. You can use OIDC to enable single sign-on (SSO) between your OAuth-enabled applications through the use of a security token called an *ID token*.
18
18
19
-
OpenID Connect introduces a type of security token called an *ID token* that allows the client application to verify the identity of a user. The ID token includes information (claims) about an authenticated user, and the user's information is also made available at the OIDC [UserInfo endpoint](userinfo.md).
20
-
21
-
The full OIDC specification is available on the OpenID Foundation's website at [OpenID Connect Core 1.0 specification](https://openid.net/specs/openid-connect-core-1_0.html).
19
+
The full specification for OIDC is available on the OpenID Foundation's website at [OpenID Connect Core 1.0 specification](https://openid.net/specs/openid-connect-core-1_0.html).
22
20
23
21
## Protocol flow: Sign-in
24
22
25
-
This diagram shows the basic OpenID Connect sign-in flow. The steps in the flow are described in detail in the sections that follow.
23
+
This diagram shows the basic OpenID Connect sign-in flow. The steps in the flow are described in more detail in later sections of the article.
24
+
25
+


29
+
## Enable ID tokens
30
+
31
+
The *ID token* introduced by OpenID Connect is issued by the authorization server (the Microsoft identity platform) when the client application requests one during user authentication. The ID token enables a client application to verify the identity of user and to get other information (claims) about the user.
32
+
33
+
ID tokens aren't issued by default for an application registered with the Microsoft identity platform. Enable ID tokens for an app by using one of the following methods.
34
+
35
+
To enable ID tokens for your app, navigate to the [Azure portal](https://portal.azure.com) and then:
1. Set `oauth2AllowIdTokenImplicitFlow` to `true` in the app registration's [application manifest](reference-app-manifest.md).
44
+
45
+
If you forget to enable ID tokens for your app and you request one, the Microsoft identity platform returns an `unsupported_response` error similar to:
30
46
31
-
## Requesting the OpenID Connect discovery document
47
+
*The provided value for the input parameter 'response_type' isn't allowed for this client. Expected value is 'code'*.
32
48
33
-
OpenID Connect also provides and endpoint for the [discovery of OIDC metadata](https://openid.net/specs/openid-connect-discovery-1_0.html) for a service. Client applications can use the information in metadata document to find URLs to use for authentication and the authentication service's public signing keys. Most often, an authentication library you use in your app uses the OpenID Connect discovery document without requiring your hand-coding these details into your application.
49
+
Requesting an ID token by specifying a `response_type`of `id_token` is explained in the [Send the sign-in request](#send-the-sign-in-request) later in the article.
34
50
35
-
Every app registration in Azure AD includes publicly accessible OIDC discovery documents. To determine the URL your app can use to get most of the information it needs to sign in users, append the _discovery document path_ to your app registration's _authority URL_.
51
+
## Fetch the OpenID Connect discovery document
52
+
53
+
OpenID Connect providers like the Microsoft identity platform offer an endpoint for the [discovery of OIDC metadata](https://openid.net/specs/openid-connect-discovery-1_0.html) for that provider. Client applications can use the information in metadata document to find URLs to use for authentication and the authentication service's public signing keys. It's more common (and recommended) to use an authentication library that handles working with the OpenID Connect discovery document for you than writing the code to do so.
54
+
55
+
Every app registration in Azure AD includes a publicly accessible OIDC discovery document URI. To determine the URI your app can use to get most of the information it needs to sign in users and request ID tokens, append the _discovery document path_ to your app registration's _authority URL_.
@@ -44,23 +64,30 @@ The value of `{tenant}` varies based on the application's sign-in audience as sh
44
64
|`common`|Users with both a personal Microsoft account and a work or school account from Azure AD can sign in to the application. |
45
65
|`organizations`|Only users with work or school accounts from Azure AD can sign in to the application. |
46
66
|`consumers`|Only users with a personal Microsoft account can sign in to the application. |
47
-
|`8eaef023-2b34-4da1-9baa-8bc8c9d6a490` or `contoso.onmicrosoft.com`| Only users from a specific Azure AD tenant (whether they are members in the directory with a work or school account, or they are guests in the directory with a personal Microsoft account) can sign in to the application. Either the friendly domain name of the Azure AD tenant or the tenant's GUID identifier can be used. You can also use the consumer tenant, `9188040d-6c67-4c5b-b112-36a304b66dad`, in place of the `consumers` tenant. |
67
+
|`8eaef023-2b34-4da1-9baa-8bc8c9d6a490` or `contoso.onmicrosoft.com`| Only users from a specific Azure AD tenant (either members of the directory with a work or school account or guests in the directory with a personal Microsoft account) can sign in to the application. <br/><br/>The value can be the domain name of the Azure AD tenant or the tenant ID in GUID format. You can also use the consumer tenant GUID, `9188040d-6c67-4c5b-b112-36a304b66dad`, in place of `consumers`. |
48
68
49
-
> [!TIP]
50
-
> Try it! Select [https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration](https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration) to see the OIDC discovery document for the `common` configuration.
69
+
You can also find your app's OpenID discovery document URI its app registration in the Azure portal.
70
+
71
+
To find the OIDC discovery document for your app, navigate to the [Azure portal](https://portal.azure.com) and then:
1. Locate the URI under **OpenID Connect metadata document**.
51
75
52
76
### Sample request
53
77
54
-
To call the UserInfo endpoint for the `common` authority on the Azure public cloud:
78
+
This request gets the OpenID Connect discovery metadata from the `common` authority's OIDC discovery document endpoint on the Azure public cloud:
55
79
56
80
```http
57
81
GET /common/v2.0/.well-known/openid-configuration
58
82
Host: login.microsoftonline.com
59
83
```
60
84
85
+
> [!TIP]
86
+
> Try it! To see the OIDC discovery document for the `common` authority, navigate to[https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration](https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration).
87
+
61
88
### Sample response
62
89
63
-
The metadata is returned in JSON format as shown in following example (truncated for brevity). The contents of the JSON response are described fully in the [OpenID Connect 1.0 discovery specification](https://openid.net/specs/openid-connect-discovery-1_0.html#rfc.section.4.2).
90
+
The discovery metadata is returned in JSON format as shown in following example (truncated for brevity). The metadata returned in the JSON response is described in detail in the [OpenID Connect 1.0 discovery specification](https://openid.net/specs/openid-connect-discovery-1_0.html#rfc.section.4.2).
64
91
65
92
```json
66
93
{
@@ -79,20 +106,18 @@ The metadata is returned in JSON format as shown in following example (truncated
79
106
}
80
107
```
81
108
82
-
<!-- UNCOMMENT WHEN/IF THE EXAMPLE APP REGISTRATION IS RE-ENABLED -->
109
+
<!-- UNCOMMENT WHEN THE EXAMPLE APP REGISTRATION IS RE-ENABLED -->
83
110
<!-- If your app has custom signing keys as a result of using [claims mapping](active-directory-claims-mapping.md), append the `appid` query parameter to include the `jwks_uri` claim that includes your app's signing key information. For example, `https://login.microsoftonline.com/{tenant}/v2.0/.well-known/openid-configuration?appid=6731de76-14a6-49ae-97bc-6eba6914391e` includes a `jwks_uri` of `https://login.microsoftonline.com/{tenant}/discovery/v2.0/keys?appid=6731de76-14a6-49ae-97bc-6eba6914391e`. -->
84
111
85
112
## Send the sign-in request
86
113
87
-
To authenticate the user in your web application, direct the their user-agent to the `/authorize` endpoint. The request is similar to the first leg of the [OAuth 2.0 authorization code flow](v2-oauth2-auth-code-flow.md), with these important distinctions:
114
+
To authenticate a user and request an ID token for use in your application, direct the user's user-agent to the Microsoft identity platform's _/authorize_ endpoint. The request is similar to the first leg of the [OAuth 2.0 authorization code flow](v2-oauth2-auth-code-flow.md) but with these distinctions:
88
115
89
-
* The request must include the `openid` scope in the `scope` parameter.
90
-
* The `response_type` parameter must include `id_token`.
91
-
* The request must include the `nonce` parameter.
92
-
* Select the **ID tokens (used for implicit and hybrid flows)** checkbox under **Implicit grant and hybrid flows** in **Azure Active Directory** > **App registrations** > \<your application\>**Authentication** in the Azure portal.
93
-
* Checking the ID tokens checkbox sets `oauth2AllowIdTokenImplicitFlow` to `true` in the [application manifest](reference-app-manifest.md). If you fail to select the ID tokens checkbox, an `unsupported_response` error is returned similar to: "The provided value for the input parameter 'response_type' isn't allowed for this client. Expected value is 'code'".
116
+
* Include the `openid` scope in the `scope` parameter.
117
+
* Specify `id_token` or `code+id_token` in the `response_type` parameter.
118
+
* Include the `nonce` parameter.
94
119
95
-
Example request (line breaks are included for readability only):
120
+
Example sign-in request (line breaks included only for readability):
96
121
97
122
```HTTP
98
123
GET https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize?
@@ -125,7 +150,7 @@ After the user authenticates and grants consent, the Microsoft identity platform
125
150
126
151
### Successful response
127
152
128
-
A successful response when you use `response_mode=form_post`:
153
+
A successful response when you use `response_mode=form_post` is similar to:
|`id_token`| The ID token that the app requested. You can use the `id_token` parameter to verify the user's identity and begin a session with the user. For more information about ID tokens and their contents, see the [`id_tokens` reference](id-tokens.md). |
165
+
|`id_token`| The ID token that the app requested. You can use the `id_token` parameter to verify the user's identity and begin a session with the user. For more information about ID tokens and their contents, see the [ID token reference](id-tokens.md). |
141
166
|`state`| If a `state` parameter is included in the request, the same value should appear in the response. The app should verify that the state values in the request and response are identical. |
142
167
143
168
### Error response
144
169
145
-
Error responses might also be sent to the redirect URI so the app can handle them:
170
+
Error responses might also be sent to the redirect URI so the app can handle them, for example:
146
171
147
172
```HTTP
148
173
POST /myapp/ HTTP/1.1
@@ -173,38 +198,44 @@ The following table describes error codes that can be returned in the `error` pa
173
198
174
199
## Validate the ID token
175
200
176
-
Merely receiving an ID token isn't always sufficient to authenticate the user; you may also need to validate the ID token's signature and verify its claims per your app's requirements. Like all OIDC platforms, the Microsoft identity platform uses [JSON Web Tokens (JWTs)](https://tools.ietf.org/html/rfc7519) and public key cryptography to sign ID tokens and verify they're valid.
201
+
Receiving an ID token in your app might not always be sufficient to fully authenticate the user. You might also need to validate the ID token's signature and verify its claims per your app's requirements. Like all OpenID providers, the Microsoft identity platform's ID tokens are [JSON Web Tokens (JWTs)](https://tools.ietf.org/html/rfc7519) signed by using public key cryptography.
202
+
203
+
Not all apps benefit from validating the ID token, however. Native and single-page apps (SPAs), for example, rarely benefit from validating the ID token. Someone with physical access to the device (or browser) can bypass the validation in several ways: by editing the web traffic to the device to provide fake tokens and keys or by debugging the application to skip the validation logic. On the other hand, web apps and web APIs using an ID token for authorization must validate the ID token because they're gating access to data.
177
204
178
-
Not all apps benefit from verifying the ID token - native apps and single page apps, for instance, rarely benefit from validating the ID token. Someone with physical access to the device (or browser) can bypass the validation in many ways - from editing the web traffic to the device to provide fake tokens and keys to simply debugging the application to skip the validation logic. On the other hand, web apps and APIs using an ID token to authorization must validate the ID token carefully since they are gating access to data.
205
+
If you need or choose to validate ID tokens in your application, we recommend not doing so manually, and instead using a library to parse and validate the tokens. Token validation libraries are available for most development languages, frameworks, and platforms.
179
206
180
-
Once you've validated the signature of the id_token, there are a few claims you'll be required to verify. See the [`id_token` reference](id-tokens.md) for more information, including [Validating Tokens](id-tokens.md#validating-an-id-token) and [Important Information About Signing Key Rollover](active-directory-signing-key-rollover.md). We recommend making use of a library for parsing and validating tokens - there is at least one available for most languages and platforms.
207
+
### What to validate in an ID token
181
208
182
-
You may also wish to validate additional claims depending on your scenario. Some common validations include:
209
+
In addition to validating the signature of the ID token, you should validate several of its claims as described in our [ID token reference](id-tokens.md) article and its [Validating an ID token](id-tokens.md#validating-an-id-token) section. Also see [Important information about signing key-rollover](active-directory-signing-key-rollover.md).
210
+
211
+
Other common ID token validations vary by application scenario, including:
183
212
184
213
* Ensuring the user/organization has signed up for the app.
185
214
* Ensuring the user has proper authorization/privileges
186
215
* Ensuring a certain strength of authentication has occurred, such as [multi-factor authentication](../authentication/concept-mfa-howitworks.md).
187
216
188
-
Once you have validated the id_token, you can begin a session with the user and use the claims in the id_token to obtain information about the user in your app. This information can be used for display, records, personalization, etc.
217
+
Once you've validated the ID token, you can begin a session with the user and use the claims in the ID token to obtain information about the user in your app. This information can be used for display, records, personalization, etc.
189
218
190
219
## Protocol diagram: Access token acquisition
191
220
192
-
Many web apps need to not only sign the user in, but also to access a web service on behalf of the user by using OAuth. This scenario combines OpenID Connect for user authentication while simultaneously getting an authorization code that you can use to get access tokens if you are using the OAuth authorization code flow.
221
+
Many applications need not only to sign in a user, but also access a web API on behalf of the user by using OAuth 2.0. If your app uses the authorization code grant type, this scenario combines OpenID Connect for user authentication and getting an access token for a protected resource (typically a web API) by using an OAuth 2.0 authorization code.
193
222
194
223
The full OpenID Connect sign-in and token acquisition flow looks similar to the next diagram. We describe each step in detail in the next sections of the article.
In addition to the ID token, the authenticated user's information is also made available at the OIDC [UserInfo endpoint](userinfo.md).
230
+
200
231
To acquire a token for the OIDC UserInfo endpoint, modify the sign-in request:
201
232
202
233
```HTTP
203
234
// Line breaks are for legibility only.
204
235
205
236
GET https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize?
206
237
client_id=6731de76-14a6-49ae-97bc-6eba6914391e // Your registered Application ID
207
-
&response_type=id_token%20token // this will return both an id_token and an access token
238
+
&response_type=id_token%20token // this will return both an ID token and an access token
208
239
&redirect_uri=http%3A%2F%2Flocalhost%2Fmyapp%2F // Your registered redirect URI, URL encoded
209
240
&response_mode=form_post // 'form_post' or 'fragment'
210
241
&scope=openid+profile+email // `openid` is required. `profile` and `email` provide additional information in the UserInfo endpoint the same way they do in an ID token.
@@ -242,7 +273,7 @@ Response parameters mean the same thing regardless of the flow used to acquire t
242
273
|`token_type`| Always "Bearer" |
243
274
|`expires_in`| How long until the access token expires, in seconds. |
244
275
|`scope`| The permissions granted on the access token. Note that since the UserInfo endpoint is hosted on MS Graph, there may be additional Graph scopes listed here (e.g. user.read) if they were previously granted to the app. That's because a token for a given resource always includes every permission currently granted to the client. |
245
-
|`id_token`| The ID token that the app requested. You can use the ID token to verify the user's identity and begin a session with the user. You'll find more details about ID tokens and their contents in the [`id_tokens` reference](id-tokens.md). |
276
+
|`id_token`| The ID token that the app requested. You can use the ID token to verify the user's identity and begin a session with the user. You'll find more details about ID tokens and their contents in the [ID token reference](id-tokens.md). |
246
277
|`state`| If a state parameter is included in the request, the same value should appear in the response. The app should verify that the state values in the request and response are identical. |
0 commit comments