Skip to content

Commit 9d79cff

Browse files
authored
Merge branch 'next' into keycloack-oauth-adapter
2 parents 3541321 + c55bc2c commit 9d79cff

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

adminforth/documentation/docs/tutorial/05-Plugins/11-oauth.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,49 @@ Enter a password (e.g., testpassword).
285285
Uncheck "Temporary" (so the user doesn't have to reset the password).
286286
Click "Set Password".
287287

288+
### Microsoft Adapter
289+
290+
Install Adapter:
291+
292+
```
293+
npm install @adminforth/microsoft-oauth-adapter --save
294+
```
295+
296+
297+
1. In the Microsoft [Azure Portal](https://portal.azure.com/), search for and click [App registrations](https://portal.azure.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade), then `New registration`.
298+
2. Give your application a name. This name will be visible to your users.
299+
3. Set the audience for the app to `Accounts in my organizational directory and personal Microsoft accounts`. This allows your user to log in using any Microsoft account.
300+
5. Set the Redirect URI platform to Web and enter your project's redirect URI.
301+
6. Go to your app and search `API permissions`, click `Add a permission`, select `Microsoft Graph`, select `Delegated permissions`, enable permissions: `offline_access`, `openid`, `profile`, `User.Read`, click `Add permissions`.
302+
7. Serch `Certificates & secrets`, click `New client secret` and create client secret.
303+
6. Get Application ID and Client Secret.
304+
7. Add the credentials to your `.env` file:
305+
306+
```bash
307+
MICROSOFT_OAUTH_CLIENT_ID=your_application_id
308+
MICROSOFT_OAUTH_CLIENT_SECRET=your_microsoft_client_secret
309+
```
310+
311+
Add the adapter to your plugin configuration:
312+
313+
```typescript title="./resources/adminuser.ts"
314+
import AdminForthAdapterMicrosoftOauth2 from '@adminforth/microsoft-oauth-adapter';
315+
316+
// ... existing resource configuration ...
317+
plugins: [
318+
new OAuthPlugin({
319+
adapters: [
320+
...
321+
new AdminForthAdapterMicrosoftOauth2({
322+
clientID: process.env.MICROSOFT_CLIENT_ID,
323+
clientSecret: process.env.MICROSOFT_CLIENT_SECRET,
324+
useOpenID: true,
325+
}),
326+
],
327+
}),
328+
]
329+
```
330+
288331
### Need custom provider?
289332

290333
Just fork any existing adapter e.g. [Google](https://github.com/devforth/adminforth-google-oauth-adapter) and adjust it to your needs.

dev-demo/resources/users.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import AdminForthAdapterGithubOauth2 from "../../adapters/adminforth-github-oau
1818

1919
import AdminForthAdapterFacebookOauth2 from "../../adapters/adminforth-facebook-oauth-adapter";
2020
import AdminForthAdapterKeycloakOauth2 from "../../adapters/adminforth-keycloak-oauth-adapter";
21+
import AdminForthAdapterMicrosoftOauth2 from "../../adapters/adminforth-microsoft-oauth-adapter";
22+
2123
export default {
2224
dataSource: "maindb",
2325
table: "users",
@@ -108,6 +110,10 @@ export default {
108110
clientSecret: process.env.KEYCLOAK_CLIENT_SECRET,
109111
keycloakUrl: process.env.KEYCLOAK_URL,
110112
realm: process.env.KEYCLOAK_REALM,
113+
}),
114+
new AdminForthAdapterMicrosoftOauth2({
115+
clientID: process.env.MICROSOFT_CLIENT_ID,
116+
clientSecret: process.env.MICROSOFT_CLIENT_SECRET,
111117
useOpenID: true,
112118
}),
113119
],

0 commit comments

Comments
 (0)