@next-auth-oauth/authing
Version:
`next-auth-oauth` 是一个基于 Next.js 和 NextAuth 的增强插件,用于简化和增强授权登录的处理。该插件提供了丰富的功能,包括第三方登录绑定、账户管理等,使得授权流程更加高效和灵活。
48 lines (47 loc) • 1.53 kB
JavaScript
import { AuthError } from 'next-auth';
/**
* Authing 授权登录服务
*
* [Authing开通应用](打开:https://www.authing.cn/)
*
* @param options
* @returns
*/
export function Authing(options = {}) {
const { clientId = process.env.AUTH_AUTHING_ID, clientSecret = process.env.AUTH_AUTHING_SECRET, checks = ['state'], domain = process.env.AUTH_AUTHING_DOMAIN, ...rest } = Object.assign({
domain: process.env.AUTH_AUTHING_DOMAIN,
clientId: process.env.AUTH_AUTHING_ID,
clientSecret: process.env.AUTH_AUTHING_SECRET,
}, options);
// 检测domain是否配置
if (!domain) {
throw new AuthError('Invalid AuthingDomain,like https://xxx.authing.cn');
}
return {
id: 'authing',
name: 'Authing',
type: 'oidc',
style: { logo: '/providers/Authing.jpg', bg: '#fff', text: '#000' },
checks: checks,
clientId,
clientSecret,
idToken: true,
issuer: domain + '/oidc',
jwks_endpoint: domain + '/oidc/.well-known/jwks.json',
authorization: {
params: {
scope: 'openid email username profile phone',
},
},
wellKnown: domain + '/oidc/.well-known/openid-configuration',
profile: (profile) => {
return {
id: profile.sub + '',
name: profile.nickname ?? profile.sub,
email: profile.email,
image: profile.picture,
};
},
...rest,
};
}