Skip to content

Commit c55bc2c

Browse files
authored
Merge pull request #160 from devforth/microsoft-oauth-adapter
docs: add Microsoft OAuth adapter installation and configuration inst…
2 parents 1845030 + 8cf4c98 commit c55bc2c

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
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
@@ -175,6 +175,49 @@ plugins: [
175175
```
176176

177177

178+
### Microsoft Adapter
179+
180+
Install Adapter:
181+
182+
```
183+
npm install @adminforth/microsoft-oauth-adapter --save
184+
```
185+
186+
187+
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`.
188+
2. Give your application a name. This name will be visible to your users.
189+
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.
190+
5. Set the Redirect URI platform to Web and enter your project's redirect URI.
191+
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`.
192+
7. Serch `Certificates & secrets`, click `New client secret` and create client secret.
193+
6. Get Application ID and Client Secret.
194+
7. Add the credentials to your `.env` file:
195+
196+
```bash
197+
MICROSOFT_OAUTH_CLIENT_ID=your_application_id
198+
MICROSOFT_OAUTH_CLIENT_SECRET=your_microsoft_client_secret
199+
```
200+
201+
Add the adapter to your plugin configuration:
202+
203+
```typescript title="./resources/adminuser.ts"
204+
import AdminForthAdapterMicrosoftOauth2 from '@adminforth/microsoft-oauth-adapter';
205+
206+
// ... existing resource configuration ...
207+
plugins: [
208+
new OAuthPlugin({
209+
adapters: [
210+
...
211+
new AdminForthAdapterMicrosoftOauth2({
212+
clientID: process.env.MICROSOFT_CLIENT_ID,
213+
clientSecret: process.env.MICROSOFT_CLIENT_SECRET,
214+
useOpenID: true,
215+
}),
216+
],
217+
}),
218+
]
219+
```
220+
178221
### Need custom provider?
179222

180223
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import AdminForthAdapterGoogleOauth2 from "../../adapters/adminforth-google-oaut
1717
import AdminForthAdapterGithubOauth2 from "../../adapters/adminforth-github-oauth-adapter";
1818

1919
import AdminForthAdapterFacebookOauth2 from "../../adapters/adminforth-facebook-oauth-adapter";
20-
20+
import AdminForthAdapterMicrosoftOauth2 from "../../adapters/adminforth-microsoft-oauth-adapter";
2121
export default {
2222
dataSource: "maindb",
2323
table: "users",
@@ -94,17 +94,20 @@ export default {
9494
new AdminForthAdapterGithubOauth2({
9595
clientID: process.env.GITHUB_CLIENT_ID,
9696
clientSecret: process.env.GITHUB_CLIENT_SECRET,
97-
redirectUri: 'http://localhost:3000/oauth/callback',
9897
}),
9998
new AdminForthAdapterGoogleOauth2({
10099
clientID: process.env.GOOGLE_CLIENT_ID,
101100
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
102-
redirectUri: 'http://localhost:3000/oauth/callback',
103101
}),
104102
new AdminForthAdapterFacebookOauth2({
105103
clientID: process.env.FACEBOOK_CLIENT_ID,
106104
clientSecret: process.env.FACEBOOK_CLIENT_SECRET,
107105
}),
106+
new AdminForthAdapterMicrosoftOauth2({
107+
clientID: process.env.MICROSOFT_CLIENT_ID,
108+
clientSecret: process.env.MICROSOFT_CLIENT_SECRET,
109+
useOpenID: true,
110+
}),
108111
],
109112
emailField: 'email',
110113
emailConfirmedField: 'email_confirmed'

0 commit comments

Comments
 (0)