|
| 1 | +--- |
| 2 | +sidebar_position: 430 |
| 3 | +title: Azure AD/ Entra ID OAuth2 |
| 4 | +--- |
| 5 | + |
| 6 | +Tutorial for OAuth2 config with Entra ID or Azure AD |
| 7 | +===================================================== |
| 8 | + |
| 9 | +This section is a basic step-by-step tutorial for OAuth2 config with Entra ID |
| 10 | + |
| 11 | +Prerequisites |
| 12 | +-------------- |
| 13 | + |
| 14 | +- Simplicité instance with designer access |
| 15 | +- A test account in your Entra ID organisation to test the login |
| 16 | + |
| 17 | +Tutorial |
| 18 | +-------- |
| 19 | + |
| 20 | +### 1) New app registration |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +### 2) Register |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | +### 3) Locate some of the endpoint data |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +NB: depending on the "supported account types" selected on step 2, your authorisation and token URLs might or might not contain the tenant ID |
| 33 | + |
| 34 | +### 4) Generate and save secret |
| 35 | + |
| 36 | +**Warning:** The secret value only shows once, make sure to copy it |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +### 5) Authorise user on your app (add claims) |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | +### 6) Add Azure as an Authentication Provider through the `AUTH_PROVIDERS` System Parameter |
| 45 | + |
| 46 | +For [security reasons](../security.md#secrets) we recommend transmitting secrets to the platform as environment variables. |
| 47 | + |
| 48 | +Set `oauth2_client_id` `oauth2_client_secret` `oauth2_authorize_url` and `oauth2_token_url` with the values from previous steps (blue marks) |
| 49 | + |
| 50 | +```json |
| 51 | +[ |
| 52 | + { "name": "simplicite", "type": "internal", "visible": true }, |
| 53 | + { |
| 54 | + "name": "azuread", |
| 55 | + "type": "oauth2", |
| 56 | + "label": "Sign in with AzureAD (OAuth2)", |
| 57 | + "client_id": "[ENV:oauth2_client_id]", |
| 58 | + "client_secret": "[ENV:oauth2_client_secret]", |
| 59 | + "authorize_url": "[ENV:oauth2_authorize_url]", |
| 60 | + "token_url": "[ENV:oauth2_token_url]", |
| 61 | + "logout_url": "https://login.microsoftonline.com/common/oauth2/v2.0/logout", |
| 62 | + "userinfo_url": "https://graph.microsoft.com/oidc/userinfo", |
| 63 | + "userinfo_mappings": { |
| 64 | + "login":"email" |
| 65 | + }, |
| 66 | + |
| 67 | + "sync": true, |
| 68 | + "visible": true |
| 69 | + } |
| 70 | +] |
| 71 | + |
| 72 | +``` |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | +:::note[Notes] |
| 77 | +To avoid Simplicité mapping account pictures you can map `picture` to `none` in `userinfo_mappings`: |
| 78 | + |
| 79 | +```json |
| 80 | +"userinfo_mappings": { |
| 81 | + "login":"email", |
| 82 | + "picture":"none" |
| 83 | +}, |
| 84 | + |
| 85 | +``` |
| 86 | + |
| 87 | +::: |
| 88 | + |
| 89 | +### 7) Implement some group attribution |
| 90 | + |
| 91 | +**_This step needs customisation to fit your own scenario_** |
| 92 | + |
| 93 | +```java |
| 94 | +package com.simplicite.commons.Application; |
| 95 | + |
| 96 | +import java.util.*; |
| 97 | +import com.simplicite.util.*; |
| 98 | +import com.simplicite.util.tools.*; |
| 99 | + |
| 100 | +/** |
| 101 | + * Platform Hooks |
| 102 | + */ |
| 103 | +public class PlatformHooks extends com.simplicite.util.engine.PlatformHooksInterface { |
| 104 | + @Override |
| 105 | + public void preLoadGrant(Grant g) { |
| 106 | + if("azuread".equals(g.getSessionInfo().getProvider())){ |
| 107 | + String userId = Grant.getUserId(g.getLogin()); |
| 108 | + Grant.removeAllResponsibilities(userId); |
| 109 | + Grant.addResponsibility(userId, "DEMO_ADMIN"); |
| 110 | + AppLog.info("Detected AzureAD login : " + g.getLogin() + " (" + userId + "). Forcing responsibilities.", null); |
| 111 | + } |
| 112 | + } |
| 113 | +} |
| 114 | + |
| 115 | +``` |
| 116 | + |
| 117 | +### 8) Add and map custom claims |
| 118 | + |
| 119 | +You can add custom JWT claims and map them to user fields. |
| 120 | + |
| 121 | +Update the `AUTH_PROVIDERS` system parameter to map these claims: |
| 122 | + |
| 123 | +```json |
| 124 | +[ |
| 125 | + { "name": "simplicite", "type": "internal", "visible": true }, |
| 126 | + { |
| 127 | + "name": "azuread", |
| 128 | + "type": "oauth2", |
| 129 | + "label": "Sign in with AzureAD (OAuth2)", |
| 130 | + "client_id": "[ENV:oauth2_client_id]", |
| 131 | + "client_secret": "[ENV:oauth2_client_secret]", |
| 132 | + "authorize_url": "[ENV:oauth2_authorize_url]", |
| 133 | + "token_url": "[ENV:oauth2_token_url]", |
| 134 | + "logout_url": "https://login.microsoftonline.com/common/oauth2/v2.0/logout", |
| 135 | + "userinfo_url": "https://graph.microsoft.com/oidc/userinfo", |
| 136 | + "userinfo_mappings": { |
| 137 | + "picture":"none" |
| 138 | + }, |
| 139 | + "jwt_claims_mappings": { |
| 140 | + "login":"email" |
| 141 | + }, |
| 142 | + "sync": true, |
| 143 | + "visible": true |
| 144 | + } |
| 145 | +] |
| 146 | +``` |
0 commit comments