Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/providers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import Basecamp from './basecamp'
import BattleNet from './battlenet'
import Box from './box'
import Bungie from './bungie'
import Credentials from './credentials'
import Cognito from './cognito'
import Credentials from './credentials'
import Discord from './discord'
import Email from './email'
import Facebook from './facebook'
Expand All @@ -27,19 +27,20 @@ import Spotify from './spotify'
import Strava from './strava'
import Twitch from './twitch'
import Twitter from './twitter'
import VK from './vk'
import Yandex from './yandex'

export default {
Apple,
Atlassian,
Auth0,
Apple,
AzureADB2C,
Basecamp,
BattleNet,
Box,
Bungie,
Credentials,
Cognito,
Credentials,
Discord,
Email,
Facebook,
Expand All @@ -57,7 +58,8 @@ export default {
Slack,
Spotify,
Strava,
Twitter,
Twitch,
Twitter,
VK,
Yandex
}
30 changes: 30 additions & 0 deletions src/providers/vk.js
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
}
}
4 changes: 2 additions & 2 deletions src/server/lib/oauth/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ async function getOAuth2 (provider, accessToken, results) {
if (this._useAuthorizationHeaderForGET) {
headers.Authorization = this.buildAuthHeader(accessToken)

// Mail.ru requires 'access_token' as URL request parameter
if (provider.id === 'mailru') {
// Mail.ru & vk.com require 'access_token' as URL request parameter
if (['mailru', 'vk'].includes(provider.id)) {
const safeAccessTokenURL = new URL(url)
safeAccessTokenURL.searchParams.append('access_token', accessToken)
url = safeAccessTokenURL.href
Expand Down
1 change: 1 addition & 0 deletions www/docs/configuration/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ NextAuth.js is designed to work with any OAuth service, it supports OAuth 1.0, 1
* [Strava](/providers/strava)
* [Twitch](/providers/Twitch)
* [Twitter](/providers/twitter)
* [VK](/providers/vk)
* [Yandex](/providers/yandex)

### Using a built-in OAuth provider
Expand Down
49 changes: 49 additions & 0 deletions www/docs/providers/vk.md
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}`,
})
]
...
```
1 change: 1 addition & 0 deletions www/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ module.exports = {
'providers/strava',
'providers/twitch',
'providers/twitter',
'providers/vk',
'providers/yandex'
]
}
Expand Down