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
In this quickstart, you'll learn how to integrate a Java web application with the Microsoft identity platform. Your app
26
-
will sign in a user, get an access token to call the Microsoft Graph API, and make a request to the Microsoft Graph API.
25
+
In this quickstart, you'll learn how to integrate a Java web application with the Microsoft identity platform. Your app will sign in a user, get an access token to call the Microsoft Graph API, and make a request to the Microsoft Graph API.
27
26
28
-
When you've completed the guide, your application will accept sign-ins of personal Microsoft accounts (including outlook.com,
29
-
live.com, and others) and work or school accounts from any company or organization that uses Azure Active Directory.
27
+
When you've completed this quickstart, your application will accept sign-ins of personal Microsoft accounts (including outlook.com, live.com, and others) and work or school accounts from any company or organization that uses Azure Active Directory.
30
28
31
29

32
30
33
31
## Prerequisites
34
32
35
33
To run this sample you will need:
34
+
36
35
-[Java Development Kit (JDK)](https://openjdk.java.net/) 8 or greater, and [Maven](https://maven.apache.org/).
36
+
- An Azure Active Directory (Azure AD) tenant. For more information on how to get an Azure AD tenant, see [How to get an Azure AD tenant](https://azure.microsoft.com/documentation/articles/active-directory-howto-tenant/).
37
37
38
38
> [!div renderon="docs"]
39
39
> ## Register and download your quickstart app
40
40
> You have two options to start your quickstart application: express (Option 1), or manual (Option 2)
41
41
>
42
42
> ### Option 1: Register and auto configure your app and then download your code sample
43
-
>
43
+
>
44
44
> 1. Go to the [Azure portal - App registrations](https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredApps).
45
45
> 1. Enter a name for your application and select **Register**.
46
46
> 1. Follow the instructions to download and automatically configure your new application.
47
-
>
47
+
>
48
48
> ### Option 2: Register and manually configure your application and code sample
49
49
>
50
-
>
51
50
> #### Step 1: Register your application
51
+
>
52
52
> To register your application and manually add the app's registration information to your solution, follow these steps:
53
-
>
53
+
>
54
54
> 1. Sign in to the [Azure portal](https://portal.azure.com) using either a work or school account, or a personal Microsoft account.
55
55
> 1. If your account gives you access to more than one tenant, select your account in the top right corner, and set your portal session to the desired Azure AD tenant.
56
-
> 1. Navigate to the Microsoft identity platform for developers [App registrations](https://go.microsoft.com/fwlink/?linkid=2083908) page.
56
+
>
57
+
> 1. Navigate to the Microsoft identity platform for developers [App registrations](https://go.microsoft.com/fwlink/linkid=2083908) page.
57
58
> 1. Select **New registration**.
58
59
> 1. When the **Register an application** page appears, enter your application's registration information:
59
60
> - In the **Name** section, enter a meaningful application name that will be displayed to users of the app, for example `java-webapp`.
60
61
> - Leave **Redirect URI** blank for now, and select **Register**.
61
-
> 1. Find the **Application (client) ID** value of the application. Copy this value, you will need it later.
62
-
> 1. Find the **Directory (tenant) ID** value of the application. Copy this value, you will need it later.
63
-
> 1. Select the **Authentication** menu, and then add the following information:
64
-
> - In **Redirect URIs**, add `http://localhost:8080/msal4jsamples/secure/aad` and `https://localhost:8080/msal4jsamples/graph/users`.
62
+
> 1. On the **Overview** page, find the **Application (client) ID** and the **Directory (tenant) ID** values of the application. Copy these values for later.
63
+
> 1. Select the **Authentication** from the menu, and then add the following information:
64
+
> - In **Redirect URIs**, add `http://localhost:8080/msal4jsamples/secure/aad` and `https://localhost:8080/msal4jsamples/graph/me`.
65
65
> - Select **Save**.
66
-
> 1.On the left hand menu, choose **Certificates & secrets** and click on**New client secret**in the **Client Secrets** section:
67
-
>
68
-
> - Type a key description (of instance app secret).
69
-
> - Select a key duration of **In 1 year**.
70
-
> -When you click on **Add**, the key value will be displayed.
71
-
> - Copy the value of the key, you will need it later.
66
+
> 1.Select the **Certificates & secrets**from the menu and in the**Client secrets**section, click on **New client secret**:
67
+
>
68
+
> - Type a key description (for instance app secret).
69
+
> - Select a key duration **In 1 year**.
70
+
> -The key value will display when you select **Add**.
71
+
> - Copy the value of the key for later. This key value will not be displayed again, nor retrievable by any other means, so record it as soon as it is visible from the Azure portal.
72
72
>
73
73
> [!div class="sxs-lookup" renderon="portal"]
74
74
> #### Step 1: Configure your application in the Azure portal
75
+
>
75
76
> For the code sample for this quickstart to work, you need to:
76
-
> 1. Add reply URLs as `http://localhost:8080/msal4jsamples/secure/aad` and `https://localhost:8080/msal4jsamples/graph/users`.
77
+
>
78
+
> 1. Add reply URLs as `http://localhost:8080/msal4jsamples/secure/aad` and `https://localhost:8080/msal4jsamples/graph/me`.
@@ -82,18 +84,23 @@ To run this sample you will need:
82
84
> >  Your application is configured with these attributes.
83
85
84
86
#### Step 2: Download the code sample
85
-
87
+
86
88
[Download the Code Sample](https://github.com/Azure-Samples/ms-identity-java-webapp/archive/master.zip)
87
-
88
-
#### Step 3: Configure the code sample
89
-
89
+
90
+
#### Step 3: Configure the code sample
91
+
90
92
1. Extract the zip file to a local folder.
91
93
1. If you use an integrated development environment, open the sample in your favorite IDE (optional).
92
-
1. Open the **application.properties** file, which can be found in *src/main/resources/*.
93
-
1. Replace application properties.
94
-
1. Find `aad.clientId` and update the value of `Enter_the_Application_Id_here` with the **Application (client) ID** value of the application you registered.
95
-
1. Find `aad.authority` and update the value of `Enter_the_Tenant_Name_Here` with the **Directory (tenant) ID** value of the application you registered.
96
-
1. Find `aad.secretKey` and update the value of `Enter_the_Client_Secret_Here` with the **Client Secret** you created in **Certificates & Secrets** for the application you registered.
94
+
95
+
1. Open the application.properties file, which can be found in src/main/resources/ folder and replace the value of the fields *aad.clientId*, *aad.authority* and *aad.secretKey* with the respective values of **Application Id**, **Tenant Id** and **Client Secret** as the following:
@@ -103,17 +110,31 @@ To run this sample you will need:
103
110
> - `Enter_the_Tenant_Name_Here` - is the **Directory (tenant) ID** value of the application you registered.
104
111
105
112
#### Step 4: Run the code sample
106
-
1. Run the code sample, and open a browser and navigate to *http://localhost:8080*.
107
-
1. The front page contains a **sign-in** button. Click on the **sign-in** button to redirect to Azure Active Directory. The user will be prompted for their credentials.
108
-
1. After successfully authenticating on Azure Active Directory, they will be redirected to *http://localhost:8080/msal4jsamples/secure/aad*. They are officially signed in to the application, and the page should show information for the signed in account. It will also contain buttons for:
109
-
-*Sign Out*: Will sign out the current user from the application, and redirect them the home page.
110
-
-*Show Users*: Will acquire a token for the Microsoft Graph, then call the Microsoft Graph with the token attached to the request to get all of the users in the tenant.
113
+
114
+
To run the project, you can either:
115
+
116
+
Run it directly from your IDE by using the embedded spring boot server or package it to a WAR file using [maven](https://maven.apache.org/plugins/maven-war-plugin/usage.html) and deploy it to a J2EE container solution such as [Apache Tomcat](http://tomcat.apache.org/).
117
+
118
+
##### Running from IDE
119
+
120
+
If you are running the web application from an IDE, click on run, then navigate to the home page of the project. For this sample, the standard home page URL is http://localhost:8080
121
+
122
+
1. On the front page, select the **Login** button to redirect to Azure Active Directory and prompt the user for their credentials.
123
+
124
+
1. After the user is authenticated, they are redirected to *http://localhost:8080/msal4jsamples/secure/aad*. They are now signed in, and the page will show information about the signed-in account. The sample UI has the following buttons:
125
+
- *Sign Out*: Signs the current user out of the application and redirects them to the home page.
126
+
- *Show User Info*: Acquires a token for Microsoft Graph and calls Microsoft Graph with a request containing the token, which returns basic information about the signed-in user.
127
+
128
+
> [!IMPORTANT]
129
+
> This quickstart application uses a client secret to identify itself as confidential client. Because the client secret is added as a plain-text to your project files, for security reasons it is recommended that you use a certificate instead of a client secret before considering the application as production application. For more information on how to use a certificate, see [Certificate credentials for application authentication](https://docs.microsoft.com/azure/active-directory/develop/active-directory-certificate-credentials).
111
130
112
131
## More information
113
132
114
133
### Getting MSAL
115
-
MSAL4J is the library used to sign in users and request tokens used to access an API protected by the Microsoft identity Platform.
116
-
You can add MSAL4J to your application by using Maven or Gradle to manage your dependencies by making the following changes to the pom.xml or build.gradle file in your application.
134
+
135
+
MSAL4J is the Java library used to sign in users and request tokens used to access an API protected by the Microsoft identity Platform.
136
+
137
+
Add MSAL4J to your application by using Maven or Gradle to manage your dependencies by making the following changes to the application's pom.xml (Maven) or build.gradle (Gradle) file.
117
138
118
139
```XML
119
140
<dependency>
@@ -127,9 +148,9 @@ You can add MSAL4J to your application by using Maven or Gradle to manage your d
0 commit comments