diff --git a/src/providers/index.js b/src/providers/index.js index 1c22fa4d21..d22629e2d8 100644 --- a/src/providers/index.js +++ b/src/providers/index.js @@ -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' @@ -37,6 +38,7 @@ export default { Google, IdentityServer4, LinkedIn, + MailRu, Mixer, Okta, Slack, diff --git a/src/providers/mailru.js b/src/providers/mailru.js new file mode 100644 index 0000000000..7c2f42347d --- /dev/null +++ b/src/providers/mailru.js @@ -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 + } +} diff --git a/src/server/lib/oauth/callback.js b/src/server/lib/oauth/callback.js index 474efd4c74..f23dfb2f77 100644 --- a/src/server/lib/oauth/callback.js +++ b/src/server/lib/oauth/callback.js @@ -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 diff --git a/www/docs/configuration/callbacks.md b/www/docs/configuration/callbacks.md index 71a0faf2a0..93f528cbcb 100644 --- a/www/docs/configuration/callbacks.md +++ b/www/docs/configuration/callbacks.md @@ -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) + } } ``` diff --git a/www/docs/configuration/providers.md b/www/docs/configuration/providers.md index 05b7f21577..f96b950d13 100644 --- a/www/docs/configuration/providers.md +++ b/www/docs/configuration/providers.md @@ -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) @@ -218,7 +219,7 @@ The Credentials provider can only be used if JSON Web Tokens are enabled for ses ::: -export const Image = ({ children, src, alt = '' }) => ( +export const Image = ({ children, src, alt = '' }) => (