Skip to content

Commit 8b1b1bf

Browse files
authored
Move all the Spring related samples to Azure Samples
Move all the Spring related samples to Azure Samples
2 parents 88a3751 + 59ec2cd commit 8b1b1bf

File tree

422 files changed

+26338
-146
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

422 files changed

+26338
-146
lines changed

.gitignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,35 @@ MigrationBackup/
348348

349349
# Ionide (cross platform F# VS Code tools) working folder
350350
.ionide/
351+
### Java template
352+
# Compiled class file
353+
*.class
354+
355+
# Log file
356+
*.log
357+
358+
# BlueJ files
359+
*.ctxt
360+
361+
# Mobile Tools for Java (J2ME)
362+
.mtj.tmp/
363+
364+
# Package Files #
365+
*.jar
366+
*.war
367+
*.nar
368+
*.ear
369+
*.zip
370+
*.tar.gz
371+
*.rar
372+
373+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
374+
hs_err_pid*
375+
376+
/.idea/*
377+
.idea/*
378+
.idea
379+
target
380+
.classpath
381+
.project
382+
*.iml

CHANGELOG.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 0 additions & 76 deletions
This file was deleted.

README.md

Lines changed: 0 additions & 57 deletions
This file was deleted.
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
---
2+
page_type: sample
3+
languages:
4+
- java
5+
products:
6+
- azure-active-directory-b2c
7+
description: "Sample project for Azure AD B2C Spring Boot client library"
8+
urlFragment: "azure-spring-boot-sample-active-directory-b2c-oidc"
9+
---
10+
11+
# Sample for Azure AD B2C Spring Boot client library for Java
12+
13+
## Key concepts
14+
This sample illustrates how to use `azure-spring-boot-starter-active-directory-b2c` package to work with OAuth 2.0 and OpenID Connect protocols with Azure Active Diretory B2C.
15+
16+
## Getting started
17+
18+
19+
20+
### Create your Azure Active Directory B2C tenant
21+
22+
Follow the guide of [AAD B2C tenant creation](https://docs.microsoft.com/azure/active-directory-b2c/tutorial-create-tenant).
23+
24+
### Register your Azure Active Directory B2C application
25+
26+
Follow the guide of [AAD B2C application registry](https://docs.microsoft.com/azure/active-directory-b2c/tutorial-register-applications).
27+
Please ensure that your b2c application's `Redirect URL` is configured to `http://localhost:8080/login/oauth2/code/`.
28+
29+
### Create user flows
30+
31+
Follow the guide of [AAD B2C user flows creation](https://docs.microsoft.com/azure/active-directory-b2c/tutorial-create-user-flows).
32+
33+
## Examples
34+
### Configure the sample
35+
36+
#### application.yml
37+
38+
1. Fill in `${your-tenant-authorization-server-base-uri}` from **Azure AD B2C** portal `App registrations` blade, select **Endpoints**, copy the base endpoint uri(Global cloud format may looks like
39+
`https://{your-tenant-name}.b2clogin.com/{your-tenant-name}.onmicrosoft.com`, China Cloud looks like `https://{your-tenant-name}.b2clogin.cn/{your-tenant-name}.partner.onmschina.cn`).
40+
41+
**NOTE**: The `azure.activedirectory.b2c.tenant` has been deprecated. Please use `azure.activedirectory.b2c.base-uri` instead.
42+
43+
2. Select one registered instance under `Applications` from portal, and then:
44+
1. Fill in `${your-client-id}` from `Application ID`.
45+
2. Fill in `${your-client-secret}` from one of `Keys`.
46+
3. Add your user flows defined on the Azure Portal under the `user-flows` configuration, which is a map, you can give each user flow a key and the value will be the name of user flow defined in AAD B2C.
47+
By default, we use the key `sign-up-or-sign-in` for a **login** user flow and `password-reset` for the **Password reset** type user flow, you can choose to override them.
48+
4. Fill in `${your-login-user-flow-key}` with the key of your login user flow, we will use the value `sign-up-or-sign-in` to look up the user-flows map if this property is not provided.
49+
5. Replace `${your-logout-success-url}` to `http://localhost:8080/login`.
50+
51+
```yaml
52+
azure:
53+
activedirectory:
54+
b2c:
55+
base-uri: ${your-tenant-authorization-server-base-uri}
56+
client-id: ${your-client-id}
57+
client-secret: ${your-client-secret}
58+
login-flow: ${your-login-user-flow-key} # default to sign-up-or-sign-in, will look up the user-flows map with provided key.
59+
logout-success-url: ${your-logout-success-url}
60+
user-flows:
61+
password-reset: ${your-profile-edit-user-flow}
62+
profile-edit: ${your-password-reset-user-flow}
63+
sign-up-or-sign-in: ${your-sign-up-or-in-user-flow}
64+
user-name-attribute-name: ${your-user-name-claim}
65+
```
66+
67+
**NOTE**: If both `tenant` and `baseUri` are configured at the same time, only `baseUri` takes effect.
68+
69+
### Run with Maven
70+
```
71+
cd azure-spring-boot-samples/aad/azure-spring-boot-sample-active-directory-b2c-oidc
72+
mvn spring-boot:run
73+
```
74+
75+
### Validation
76+
77+
1. Access `http://localhost:8080/` as index page.
78+
2. Sign up/in.
79+
3. Profile edit.
80+
4. Password reset.
81+
5. Log out.
82+
6. Sign in.
83+
84+
## Troubleshooting
85+
- `Missing attribute 'name' in attributes `
86+
87+
```
88+
java.lang.IllegalArgumentException: Missing attribute 'name' in attributes
89+
at org.springframework.security.oauth2.core.user.DefaultOAuth2User.<init>(DefaultOAuth2User.java:67) ~[spring-security-oauth2-core-5.3.6.RELEASE.jar:5.3.6.RELEASE]
90+
at org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser.<init>(DefaultOidcUser.java:89) ~[spring-security-oauth2-core-5.3.6.RELEASE.jar:5.3.6.RELEASE]
91+
at org.springframework.security.oauth2.client.oidc.userinfo.OidcUserService.loadUser(OidcUserService.java:144) ~[spring-security-oauth2-client-5.3.6.RELEASE.jar:5.3.6.RELEASE]
92+
at org.springframework.security.oauth2.client.oidc.userinfo.OidcUserService.loadUser(OidcUserService.java:63) ~[spring-security-oauth2-client-5.3.6.RELEASE.jar:5.3.6.RELEASE]
93+
```
94+
95+
While running sample, if error occurs with logs above:
96+
97+
- make sure that while creating user workflow by following this [guide](https://docs.microsoft.com/azure/active-directory-b2c/tutorial-create-user-flows), for **User attributes and claims** , attributes and claims for **Display Name** should be chosen.
98+
99+
### FAQ
100+
101+
#### Sign in with loops to B2C endpoint ?
102+
This issue almost due to polluted cookies of `localhost`. Clean up cookies of `localhost` and try it again.
103+
104+
#### More identity providers from AAD B2C login ?
105+
Follow the guide of [Set up Google account with AAD B2C](https://docs.microsoft.com/azure/active-directory-b2c/active-directory-b2c-setup-goog-app).
106+
And also available for Amazon, Azure AD, FaceBook, Github, Linkedin and Twitter.
107+
108+
## Next steps
109+
## Contributing
110+
<!-- LINKS -->
111+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>org.springframework.boot</groupId>
8+
<artifactId>spring-boot-starter-parent</artifactId>
9+
<version>2.5.0</version> <!-- {x-version-update;org.springframework.boot:spring-boot-starter-parent;external_dependency} -->
10+
</parent>
11+
12+
<groupId>com.azure.spring</groupId>
13+
<artifactId>azure-spring-boot-sample-active-directory-b2c-oidc</artifactId>
14+
<version>1.0.0</version>
15+
<packaging>jar</packaging>
16+
17+
<name>Azure Spring Boot Starter Sample - Azure AD B2C Spring Security 5 OAuth Integration</name>
18+
<description>Azure AD B2C Spring Security 5 OAuth2 Integration Spring Boot Sample</description>
19+
<url>https://github.com/Azure/azure-sdk-for-java</url>
20+
21+
<dependencyManagement>
22+
<dependencies>
23+
<dependency>
24+
<groupId>com.azure</groupId>
25+
<artifactId>azure-core</artifactId>
26+
<version>1.18.0</version> <!-- {x-version-update;com.azure:azure-core;dependency} -->
27+
</dependency>
28+
</dependencies>
29+
</dependencyManagement>
30+
31+
<dependencies>
32+
<dependency>
33+
<groupId>com.azure.spring</groupId>
34+
<artifactId>azure-spring-boot-starter-active-directory-b2c</artifactId>
35+
<version>3.6.0</version> <!-- {x-version-update;com.azure.spring:azure-spring-boot-starter-active-directory-b2c;dependency} -->
36+
</dependency>
37+
38+
<dependency>
39+
<groupId>org.springframework.boot</groupId>
40+
<artifactId>spring-boot-starter-web</artifactId>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>org.springframework.boot</groupId>
45+
<artifactId>spring-boot-starter-thymeleaf</artifactId>
46+
</dependency>
47+
48+
<dependency>
49+
<groupId>org.springframework.boot</groupId>
50+
<artifactId>spring-boot-starter-security</artifactId>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>org.thymeleaf.extras</groupId>
55+
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
56+
</dependency>
57+
</dependencies>
58+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.spring.sample.aad.b2c;
5+
6+
import org.springframework.boot.SpringApplication;
7+
import org.springframework.boot.autoconfigure.SpringBootApplication;
8+
9+
@SpringBootApplication
10+
public class AzureADB2COIDCSampleApplication {
11+
12+
public static void main(String[] args) {
13+
//
14+
SpringApplication.run(AzureADB2COIDCSampleApplication.class, args);
15+
}
16+
}

0 commit comments

Comments
 (0)