Skip to content
Closed
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
2 changes: 2 additions & 0 deletions src/providers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import GitLab from './gitlab'
import Google from './google'
import IdentityServer4 from './identity-server4'
import LinkedIn from './linkedin'
import MailRu from './mailru'
import Mixer from './mixer'
import Okta from './okta'
import Slack from './slack'
Expand All @@ -37,6 +38,7 @@ export default {
Google,
IdentityServer4,
LinkedIn,
MailRu,
Mixer,
Okta,
Slack,
Expand Down
26 changes: 26 additions & 0 deletions src/providers/mailru.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export default (options) => {
return {
id: 'mailru',
name: 'Mail.ru',
type: 'oauth',
version: '2.0',
scope: 'userinfo',
params: {
grant_type: 'authorization_code'
},
accessTokenUrl: 'https://oauth.mail.ru/token',
requestTokenUrl: 'https://oauth.mail.ru/token',
authorizationUrl: 'https://oauth.mail.ru/login?response_type=code',
profileUrl: 'https://oauth.mail.ru/userinfo',
profile: (profile) => {
return {
id: profile.id,
name: profile.name,
email: profile.email,
image: profile.image,
}
},
setGetAccessTokenProfileUrl: true,
...options
}
}
8 changes: 8 additions & 0 deletions src/server/lib/oauth/callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,18 @@ async function _getOAuthAccessToken (code, provider, callback) {
function _get (provider, accessToken, callback) {
const url = provider.profileUrl
const headers = provider.headers || {}
const setGetAccessTokenProfileUrl = provider.setGetAccessTokenProfileUrl !== null ? provider.setGetAccessTokenProfileUrl : true

if (this._useAuthorizationHeaderForGET) {
headers.Authorization = this.buildAuthHeader(accessToken)

// Mail.ru requires 'access_token' as URL request parameter
if (setGetAccessTokenProfileUrl) {
if (provider.profileUrl) {
url = provider.profileUrl + '?access_token=' + accessToken
}
}

// This line is required for Twitch
headers['Client-ID'] = provider.clientId
accessToken = null
Expand Down
28 changes: 13 additions & 15 deletions www/docs/configuration/callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,19 @@ If you want to pass data such as an Access Token or User ID to the browser when
You can specify a handler for any of the callbacks below.

```js title="pages/api/auth/[...nextauth].js"
...
callbacks: {
signIn: async (user, account, profile) => {
return Promise.resolve(true)
},
redirect: async (url, baseUrl) => {
return Promise.resolve(baseUrl)
},
session: async (session, user) => {
return Promise.resolve(session)
},
jwt: async (token, user, account, profile, isNewUser) => {
return Promise.resolve(token)
}
...
callbacks: {
signIn: async (user, account, profile) => {
return Promise.resolve(true)
},
redirect: async (url, baseUrl) => {
return Promise.resolve(baseUrl)
},
session: async (session, user) => {
return Promise.resolve(session)
},
jwt: async (token, user, account, profile, isNewUser) => {
return Promise.resolve(token)
}
}
```

Expand Down
3 changes: 2 additions & 1 deletion www/docs/configuration/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ NextAuth.js is designed to work with any OAuth service, it supports OAuth 1.0, 1
* [Google](/providers/google)
* [IdentityServer4](/providers/identity-server4)
* [LinkedIn](/providers/LinkedIn)
* [Mail.ru](/providers/Mail.ru)
* [Mixer](/providers/Mixer)
* [Okta](/providers/Okta)
* [Slack](/providers/slack)
Expand Down Expand Up @@ -218,7 +219,7 @@ The Credentials provider can only be used if JSON Web Tokens are enabled for ses
:::

<!-- React Image Component -->
export const Image = ({ children, src, alt = '' }) => (
export const Image = ({ children, src, alt = '' }) => (
<div
style={{
padding: '0.2rem',
Expand Down
25 changes: 25 additions & 0 deletions www/docs/providers/mailru.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
id: Mail.ru
title: Mail.ru
---

## Documentation

https://o2.mail.ru/docs

## Configuration

https://o2.mail.ru/app/

## Example

```js
import Providers from `next-auth/providers`
...
providers: [
Providers.MailRu({
clientId: process.env.MAILRU_CLIENT_ID,
clientSecret: process.env.MAILRU_CLIENT_SECRET
})
]
...
1 change: 1 addition & 0 deletions www/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = {
'providers/google',
'providers/identity-server4',
'providers/linkedin',
'providers/Mail.ru',
'providers/mixer',
'providers/okta',
'providers/slack',
Expand Down