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
> -`Enter_the_Application_Id_here` - is the Application Id for the application you registered.
112
-
> -`Enter_the_Tenant_Info_Here` - is one of the options below:
113
-
> - If your application supports **My organization only**, replace this value with the **Tenant Id** or **Tenant name** (for example, contoso.onmicrosoft.com)
114
-
> - If your application supports **Accounts in any organizational directory**, replace this value with `organizations`
115
-
> - If your application supports **All Microsoft account users**, replace this value with `common`
116
109
> -`Enter_the_Client_Secret_Here` - is the **Client Secret** you created in **Certificates & Secrets** for the application you registered.
117
110
118
111
#### Step 4: Run the code sample
119
112
120
-
- You will need to install MSAL Python library, Flask framework, Flask-Sessions for server-side session management and requests using pip as follows:
113
+
1. You will need to install MSAL Python library, Flask framework, Flask-Sessions for server-side session management and requests using pip as follows:
121
114
122
-
```Shell
123
-
pip install msal
124
-
pip install flask
125
-
pip install Flask-Session
126
-
pip install requests
127
-
```
115
+
```Shell
116
+
pip install -r requirements.txt
117
+
```
128
118
129
-
- If the environment variable for Flask is already set:
130
-
Run app.py from shell or command line:
119
+
2. Run app.py from shell or command line:
131
120
132
-
```Shell
133
-
python app.py
134
-
```
121
+
```Shell
122
+
python app.py
123
+
```
135
124
136
-
- If the environment variable for Flask is not set:
125
+
## Next steps
137
126
138
-
1. Type the following commands on shell or command line by navigating to the project directory:
127
+
Learn more about web apps that sign in users, and then that calls web APIs:
139
128
140
-
```Shell
141
-
export FLASK_APP=app.py
142
-
export FLASK_DEBUG=1
143
-
flask run
144
-
```
129
+
> [!div class="nextstepaction"]
130
+
> [Scenario: Web apps that sign in users](scenario-web-app-sign-user-overview.md)
145
131
146
132
[!INCLUDE [Help and support](../../../includes/active-directory-develop-help-support-include.md)]
Copy file name to clipboardExpand all lines: articles/active-directory/develop/scenario-web-app-sign-user-app-configuration.md
+59-48Lines changed: 59 additions & 48 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,17 +31,36 @@ The libraries used to protect a Web App (and a Web API) are:
31
31
| Platform | Library | Description |
32
32
|----------|---------|-------------|
33
33
||[Identity model extensions for .NET](https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/wiki)| Used directly by ASP.NET and ASP.NET Core, Microsoft Identity Extensions for .NET proposes a set of DLLs running both on .NET Framework and .NET Core. From an ASP.NET/ASP.NET Core Web app, you can control token validation using the **TokenValidationParameters** class (in particular in some ISV scenarios) |
34
-
||[msal4j](https://github.com/AzureAD/microsoft-authentication-library-for-java/wiki)| MSAL for Java - currently in public preview |
35
-
||[MSAL Python](https://github.com/AzureAD/microsoft-authentication-library-for-python/wiki)| MSAL for Python - currently in public preview |
34
+
||[msal4j](https://github.com/AzureAD/microsoft-authentication-library-for-java/wiki)| MSAL for Java - currently in public preview |
35
+
||[MSAL Python](https://github.com/AzureAD/microsoft-authentication-library-for-python/wiki)| MSAL for Python - currently in public preview |
36
36
37
-
Code snippets in this article and the following are extracted from:
37
+
Select the tab corresponding to the platform you're interested in:
38
38
39
-
- the [ASP.NET Core Web app incremental tutorial, chapter 1](https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/tree/master/1-WebApp-OIDC/1-1-MyOrg).
40
-
- the [ASP.NET Web app sample](https://github.com/Azure-Samples/ms-identity-aspnet-webapp-openidconnect)
41
-
- the [Java web application calling Microsoft graph](https://github.com/Azure-Samples/ms-identity-java-webapp) msal4j web app sample
42
-
- the [Python web application calling Microsoft graph](https://github.com/Azure-Samples/ms-identity-python-webapp) MSAL.Python web app sample
39
+
# [ASP.NET Core](#tab/aspnetcore)
40
+
41
+
Code snippets in this article and the following are extracted from the [ASP.NET Core Web app incremental tutorial, chapter 1](https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/tree/master/1-WebApp-OIDC/1-1-MyOrg).
42
+
43
+
You might want to refer to this tutorial for full implementation details.
44
+
45
+
# [ASP.NET](#tab/aspnet)
46
+
47
+
Code snippets in this article and the following are extracted from the [ASP.NET Web app sample](https://github.com/Azure-Samples/ms-identity-aspnet-webapp-openidconnect)
48
+
49
+
You might want to refer to this sample for full implementation details.
50
+
51
+
# [Java](#tab/java)
52
+
53
+
Code snippets in this article and the following are extracted from the [Java web application calling Microsoft graph](https://github.com/Azure-Samples/ms-identity-java-webapp) msal4j web app sample
54
+
55
+
You might want to refer to this sample for full implementation details.
56
+
57
+
# [Python](#tab/python)
43
58
44
-
You might want to refer to these tutorials and sample for full implementation details.
59
+
Code snippets in this article and the following are extracted from the [Python web application calling Microsoft graph](https://github.com/Azure-Samples/ms-identity-python-webapp) MSAL.Python web app sample
60
+
61
+
You might want to refer to this sample for full implementation details.
62
+
63
+
---
45
64
46
65
## Configuration files
47
66
@@ -55,7 +74,7 @@ Sometimes, applications can be parametrized by the `authority`, which is the con
55
74
56
75
# [ASP.NET Core](#tab/aspnetcore)
57
76
58
-
In ASP.NET Core, these settings are located in the `appsettings.json` file, in the "AzureAD" section.
77
+
In ASP.NET Core, these settings are located in the [appsettings.json](https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/blob/bc564d68179c36546770bf4d6264ce72009bc65a/1-WebApp-OIDC/1-1-MyOrg/appsettings.json#L2-L8) file, in the "AzureAD" section.
59
78
60
79
```Json
61
80
{
@@ -82,7 +101,7 @@ In ASP.NET Core, these settings are located in the `appsettings.json` file, in t
82
101
}
83
102
```
84
103
85
-
In ASP.NET Core, there's another file (`properties\launchSettings.json`) that contains the URL (`applicationUrl`) and the SSL Port (`sslPort`) for your application and various profiles.
104
+
In ASP.NET Core, there's another file [properties\launchSettings.json](https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/blob/bc564d68179c36546770bf4d6264ce72009bc65a/1-WebApp-OIDC/1-1-MyOrg/Properties/launchSettings.json#L6-L7) that contains the URL (`applicationUrl`) and the SSL Port (`sslPort`) for your application and various profiles.
86
105
87
106
```Json
88
107
{
@@ -120,7 +139,7 @@ In the same way, the sign-out URI would be set to `https://localhost:44321/signo
120
139
121
140
# [ASP.NET](#tab/aspnet)
122
141
123
-
In ASP.NET, the application is configured through the `Web.Config` file
142
+
In ASP.NET, the application is configured through the [Web.Config](https://github.com/Azure-Samples/ms-identity-aspnet-webapp-openidconnect/blob/a2da310539aa613b77da1f9e1c17585311ab22b7/WebApp/Web.config#L12-L15) file lines 12-15
124
143
125
144
```XML
126
145
<?xml version="1.0" encoding="utf-8"?>
@@ -146,7 +165,7 @@ In the Azure portal, the reply URIs that you need to register in the **Authentic
146
165
147
166
# [Java](#tab/java)
148
167
149
-
In Java, the configuration is located in the `application.properties` file located under `src/main/resources`
168
+
In Java, the configuration is located in the [application.properties](https://github.com/Azure-Samples/ms-identity-java-webapp/blob/d55ee4ac0ce2c43378f2c99fd6e6856d41bdf144/src/main/resources/application.properties) file located under `src/main/resources`
150
169
151
170
```Java
152
171
aad.clientId=Enter_the_Application_Id_here
@@ -160,16 +179,29 @@ In the Azure portal, the reply URIs that you need to register in the **Authentic
160
179
161
180
# [Python](#tab/python)
162
181
163
-
Here is the Python configuration file in [app_config.py](https://github.com/Azure-Samples/ms-identity-python-webapp/blob/web_app_sample/app_config.py)
182
+
Here is the Python configuration file in [app_config.py](https://github.com/Azure-Samples/ms-identity-python-webapp/blob/0.1.0/app_config.py)
>raiseValueError("Need to define CLIENT_SECRET environment variable")
203
+
>```
204
+
173
205
---
174
206
175
207
## Initialization code
@@ -281,11 +313,11 @@ public static IServiceCollection AddMicrosoftIdentityPlatformAuthentication(
281
313
...
282
314
```
283
315
284
-
The `AadIssuerValidator` classenables that the issuer of the token is validated in many cases (v1.0 orv2.0 token, single-tenant, ormulti-tenantapplicationorapplicationthatsignsinuserswiththeirpersonalMicrosoftaccounts, intheAzurepubliccloudornational clouds). It's available from [Microsoft.Identity.Web/Resource/AadIssuerValidator.cs](https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/blob/master/Microsoft.Identity.Web/Resource/AadIssuerValidator.cs)
316
+
The `AadIssuerValidator`class enables that the issuer of the token is validated in many cases (v1.0 or v2.0 token, single-tenant, or multi-tenant application or application that signs in users with their personal Microsoft accounts, in the Azure public cloud,or national clouds). It's available from [Microsoft.Identity.Web/Resource/AadIssuerValidator.cs](https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/blob/master/Microsoft.Identity.Web/Resource/AadIssuerValidator.cs)
285
317
286
318
# [ASP.NET](#tab/aspnet)
287
319
288
-
The code related to authentication in ASP.NET Web app / Web APIs is located in the `App_Start/Startup.Auth.cs` file.
320
+
The code related to authentication inASP.NET Web app / Web APIs is located in the [App_Start/Startup.Auth.cs](https://github.com/Azure-Samples/ms-identity-aspnet-webapp-openidconnect/blob/a2da310539aa613b77da1f9e1c17585311ab22b7/WebApp/App_Start/Startup.Auth.cs#L17-L61) file.
289
321
290
322
```CSharp
291
323
public void ConfigureAuth(IAppBuilder app)
@@ -311,7 +343,7 @@ The code related to authentication in ASP.NET Web app / Web APIs is located in t
311
343
312
344
# [Java](#tab/java)
313
345
314
-
The Java sample uses the Spring framework. The application is protected because you implement a `Filter`, which gets each HTTP response. In the Java Web appquickstart, thisis `AuthFilter` in `src/main/java/com/microsoft/azure/msalwebsample/AuthFilter.java`. ThefilterprocesstheOAuth 2.0 authorizationcodeflowandtherefore:
346
+
The Java sample uses the Spring framework. The application is protected because you implement a `Filter`, which intercepts each HTTP response. In the Java Web app quickstart, thisfilteris`AuthFilter`in`src/main/java/com/microsoft/azure/msalwebsample/AuthFilter.java`. The filter process the OAuth 2.0 authorization code flow and therefore:
315
347
316
348
- verifies if the user is authenticated (`isAuthenticated()` method)
317
349
-if the user isn't authenticated, it computes the url of the Azure AD authorize endpoints, and redirects the browser to this URI
@@ -323,45 +355,24 @@ For details see the `doFilter()` method in [AuthFilter.java](https://github.com/
323
355
> [!NOTE]
324
356
> The code of the `doFilter()`is written in a slightly different order, but the flow is the one described.
325
357
326
-
See [MicrosoftidentityplatformandOAuth 2.0 authorizationcodeflow](v2-oauth2-auth-code-flow.md) fordetailsabouttheauthorizationcodeflowtriggeredbythismethod
358
+
See [Microsoft identity platform and OAuth 2.0 authorization code flow](v2-oauth2-auth-code-flow.md) for details about the authorization code flow, triggered by this method
The Python sample uses Flask. The initialization of flask, andMSAL.Python is done in [app.py#L1-L28](https://github.com/Azure-Samples/ms-identity-python-webapp/blob/e03be352914bfbd58be0d4170eba1fb7a4951d84/app.py#L1-L28)
ThisisMSAL.Pythonthatwilltakecareoflettingtheusersign-in. See [app.py#L74-84](https://github.com/Azure-Samples/ms-identity-python-webapp/blob/e1199b4c3cdcb637cf0d8306832efbd85492e123/app.py#L74-84)
0 commit comments