-
Notifications
You must be signed in to change notification settings - Fork 916
feat: adds azure AD as oauth2 provider #855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
title: Azure AD | ||
description: This provider is based on oauth2 scheme and supports all scheme options | ||
position: 38 | ||
category: Providers | ||
--- | ||
|
||
[Source Code](https://github.com/nuxt-community/auth-module/blob/dev/src/providers/aad/index.ts) | ||
|
||
## Usage | ||
|
||
```js | ||
auth: { | ||
strategies: { | ||
aad: { | ||
clientId: process.env.AAD_CLIENT_ID, | ||
clientSecret: process.env.AAD_CLIENT_SECRET, | ||
tenantId: process.env.AAD_TENANT_ID, | ||
grantType: 'authorization_code' | ||
}, | ||
} | ||
} | ||
``` | ||
|
||
Anywhere in your application logic: | ||
|
||
```js | ||
this.$auth.loginWith('aad') | ||
``` | ||
|
||
💁 This provider is based on [oauth2 scheme](../schemes/oauth2.md) and supports all scheme options. | ||
|
||
## Obtaining configs | ||
|
||
You need to create an app registration from Azure Portal and make sure to set up everything for an OAuth app in the usual way. e.g. whitelist urls. |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,17 @@ | ||||||||||||||
import { assignDefaults, addAuthorize } from '../../utils/provider' | ||||||||||||||
|
||||||||||||||
export default function aad (nuxt, strategy) { | ||||||||||||||
assignDefaults(strategy, { | ||||||||||||||
scheme: 'oauth2', | ||||||||||||||
endpoints: { | ||||||||||||||
authorization: `https://login.microsoftonline.com/${strategy.tenantId}/oauth2/v2.0/authorize`, | ||||||||||||||
userInfo: 'https://graph.microsoft.com/v1.0/me', | ||||||||||||||
token: `https://login.microsoftonline.com/${strategy.tenantId}/oauth2/v2.0/token` | ||||||||||||||
Comment on lines
+7
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Does this make sense @JoaoPedroAS51 @bmulholland ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think should be like this: const tenantId = strategy.tenantId || 'common'
assignDefaults(strategy, {
scheme: 'oauth2',
endpoints: {
authorization: `https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/authorize`,
userInfo: 'https://graph.microsoft.com/v1.0/me',
token: `https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/token`
},
codeChallengeMethod: 'S256',
scope: ['openid', 'profile'],
autoLogout: true
}) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, @JoaoPedroAS51's approach is much easier to read. I'd suggest a comment above the
|
||||||||||||||
}, | ||||||||||||||
codeChallengeMethod: 'S256', | ||||||||||||||
scope: ['openid', 'profile'], | ||||||||||||||
autoLogout: true | ||||||||||||||
}) | ||||||||||||||
|
||||||||||||||
addAuthorize(nuxt, strategy) | ||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Providers are not inside folders anymore. So you can move the file to
providers
dir, and rename toad.ts