-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(provider): add vk.com provider (#1060)
* feat(provider): add vk.com provider * refactor(provider): reduce vk.com provider api
- Loading branch information
1 parent
505efc8
commit e8b1513
Showing
6 changed files
with
89 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export default (options) => { | ||
const apiVersion = '5.126' // https://vk.com/dev/versions | ||
|
||
return { | ||
id: 'vk', | ||
name: 'vk.com', | ||
type: 'oauth', | ||
version: '2.0', | ||
scope: 'email', | ||
params: { | ||
grant_type: 'authorization_code' | ||
}, | ||
accessTokenUrl: `https://oauth.vk.com/access_token?v=${apiVersion}`, | ||
requestTokenUrl: `https://oauth.vk.com/access_token?v=${apiVersion}`, | ||
authorizationUrl: | ||
`https://oauth.vk.com/authorize?response_type=code&v=${apiVersion}`, | ||
profileUrl: `https://api.vk.com/method/users.get?fields=photo_100&v=${apiVersion}`, | ||
profile: (result) => { | ||
const profile = result.response?.[0] ?? {} | ||
|
||
return { | ||
id: profile.id, | ||
name: [profile.first_name, profile.last_name].filter(Boolean).join(' '), | ||
email: profile.email, | ||
image: profile.photo_100 | ||
} | ||
}, | ||
...options | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
id: vk | ||
title: vk.com | ||
--- | ||
|
||
## Documentation | ||
|
||
https://vk.com/dev/first_guide | ||
|
||
## Configuration | ||
|
||
https://vk.com/apps?act=manage | ||
|
||
## Example | ||
|
||
```js | ||
import Providers from `next-auth/providers` | ||
... | ||
providers: [ | ||
Providers.VK({ | ||
clientId: process.env.VK_CLIENT_ID, | ||
clientSecret: process.env.VK_CLIENT_SECRET | ||
}) | ||
] | ||
... | ||
``` | ||
|
||
:::note | ||
By default the provider uses `5.126` version of the API. See https://vk.com/dev/versions for more info. | ||
::: | ||
|
||
If you want to use a different version, you can pass it to provider's options object: | ||
|
||
```js | ||
// pages/api/auth/[...nextauth].js | ||
|
||
const apiVersion = "5.126" | ||
... | ||
providers: [ | ||
Providers.VK({ | ||
accessTokenUrl: `https://oauth.vk.com/access_token?v=${apiVersion}`, | ||
requestTokenUrl: `https://oauth.vk.com/access_token?v=${apiVersion}`, | ||
authorizationUrl: | ||
`https://oauth.vk.com/authorize?response_type=code&v=${apiVersion}`, | ||
profileUrl: `https://api.vk.com/method/users.get?fields=photo_100&v=${apiVersion}`, | ||
}) | ||
] | ||
... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters