Skip to content

Commit 6db53d4

Browse files
authored
Merge pull request #93261 from sangonzal/sangonzal/updateJavaWebAppQuickstart
Update Java web app quickstart
2 parents a5e9b41 + 6d3e990 commit 6db53d4

File tree

1 file changed

+62
-41
lines changed

1 file changed

+62
-41
lines changed

articles/active-directory/develop/quickstart-v2-java-webapp.md

Lines changed: 62 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -22,58 +22,60 @@ ms.custom: aaddev
2222

2323
[!INCLUDE [active-directory-develop-applies-v2](../../../includes/active-directory-develop-applies-v2.md)]
2424

25-
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.
2726

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.
3028

3129
![Shows how the sample app generated by this quickstart works](media/quickstart-v2-java-webapp/java-quickstart.svg)
3230

3331
## Prerequisites
3432

3533
To run this sample you will need:
34+
3635
- [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/).
3737

3838
> [!div renderon="docs"]
3939
> ## Register and download your quickstart app
4040
> You have two options to start your quickstart application: express (Option 1), or manual (Option 2)
4141
>
4242
> ### Option 1: Register and auto configure your app and then download your code sample
43-
>
43+
>
4444
> 1. Go to the [Azure portal - App registrations](https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredApps).
4545
> 1. Enter a name for your application and select **Register**.
4646
> 1. Follow the instructions to download and automatically configure your new application.
47-
>
47+
>
4848
> ### Option 2: Register and manually configure your application and code sample
4949
>
50-
>
5150
> #### Step 1: Register your application
51+
>
5252
> To register your application and manually add the app's registration information to your solution, follow these steps:
53-
>
53+
>
5454
> 1. Sign in to the [Azure portal](https://portal.azure.com) using either a work or school account, or a personal Microsoft account.
5555
> 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.
5758
> 1. Select **New registration**.
5859
> 1. When the **Register an application** page appears, enter your application's registration information:
5960
> - In the **Name** section, enter a meaningful application name that will be displayed to users of the app, for example `java-webapp`.
6061
> - 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`.
6565
> - 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.
7272
>
7373
> [!div class="sxs-lookup" renderon="portal"]
7474
> #### Step 1: Configure your application in the Azure portal
75+
>
7576
> 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`.
7779
> 1. Create a Client Secret.
7880
> > [!div renderon="portal" id="makechanges" class="nextstepaction"]
7981
> > [Make this change for me]()
@@ -82,18 +84,23 @@ To run this sample you will need:
8284
> > ![Already configured](media/quickstart-v2-aspnet-webapp/green-check.png) Your application is configured with these attributes.
8385
8486
#### Step 2: Download the code sample
85-
87+
8688
[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+
9092
1. Extract the zip file to a local folder.
9193
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:
96+
97+
```file
98+
aad.clientId=Enter_the_Application_Id_here
99+
aad.authority=https://login.microsoftonline.com/Enter_the_Tenant_Name_Here/
100+
aad.secretKey=Enter_the_Client_Secret_Here
101+
aad.redirectUriSignin=http://localhost:8080/msal4jsample/secure/aad
102+
aad.redirectUriGraph=http://localhost:8080/msal4jsample/graph/me
103+
```
97104
98105
> [!div renderon="docs"]
99106
> Where:
@@ -103,17 +110,31 @@ To run this sample you will need:
103110
> - `Enter_the_Tenant_Name_Here` - is the **Directory (tenant) ID** value of the application you registered.
104111
105112
#### 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).
111130
112131
## More information
113132
114133
### 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.
117138
118139
```XML
119140
<dependency>
@@ -127,9 +148,9 @@ You can add MSAL4J to your application by using Maven or Gradle to manage your d
127148
compile group: 'com.microsoft.azure', name: 'msal4j', version: '0.5.0-preview'
128149
```
129150

130-
131151
### MSAL initialization
132-
You can add the reference to MSAL4J by adding the following code to the top of the file where you will be using MSAL4J:
152+
153+
Add a reference to MSAL4J by adding the following code to the top of the file where you will be using MSAL4J:
133154

134155
```Java
135156
import com.microsoft.aad.msal4j.*;
@@ -140,16 +161,16 @@ import com.microsoft.aad.msal4j.*;
140161
Learn more about permissions and consent:
141162

142163
> [!div class="nextstepaction"]
143-
> [Permissions and Consent](https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-permissions-and-consent)
164+
> [Permissions and Consent](https://docs.microsoft.com/azure/active-directory/develop/v2-permissions-and-consent)
144165
145166
To know more about the auth flow for this scenario, see the Oauth 2.0 authorization code flow:
146167

147168
> [!div class="nextstepaction"]
148-
> [Authorization Code Oauth flow](https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow)
169+
> [Authorization Code Oauth flow](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-auth-code-flow)
149170
150171
Help us improve the Microsoft identity platform. Tell us what you think by completing a short two-question survey.
151172

152173
> [!div class="nextstepaction"]
153-
> [Microsoft identity platform survey](https://forms.office.com/Pages/ResponsePage.aspx?id=v4j5cvGGr0GRqy180BHbRyKrNDMV_xBIiPGgSvnbQZdUQjFIUUFGUE1SMEVFTkdaVU5YT0EyOEtJVi4u)
174+
> [Microsoft identity platform survey](https://forms.office.com/Pages/ResponsePage.aspxid=v4j5cvGGr0GRqy180BHbRyKrNDMV_xBIiPGgSvnbQZdUQjFIUUFGUE1SMEVFTkdaVU5YT0EyOEtJVi4u)
154175
155176
[!INCLUDE [Help and support](../../../includes/active-directory-develop-help-support-include.md)]

0 commit comments

Comments
 (0)