admin管理员组文章数量:1405918
I'm currently trying to implement two Microsoft provider with the better-auth package but I keep getting this error :
When I log with my personnal account
I verified if my callbackUrl is correctly setup in my Microsoft azure dashboard and it's the same between the dashboard callbackUrl and my app one.
There is the auth config with better-auth :
.....
const options = {
baseURL: baseURL,
database: prismaAdapter(adminPrisma, {
provider: "postgresql",
}),
emailAndPassword: {
enabled: true,
},
user: {
additionalFields: {
anizationId: {
type: "string",
},
providerId: {
type: "string",
},
},
},
session: {
cookieCache: {
enabled: true,
maxAge: 5 * 60, // Cache duration in seconds
},
fields: {
expiresAt: "expires", // e.g., "expires_at" or your existing field name
token: "sessionToken", // e.g., "session_token" or your existing field name
},
},
account: {
accountLinking: {
enabled: true,
},
fields: {
accountId: "providerAccountId",
providerId: "provider",
refreshToken: "refresh_token",
accessToken: "access_token",
accessTokenExpiresAt: "expires_at",
idToken: "id_token",
},
},
verification: {
// better auth not recognizing our model name, we have to override it
modelName: "Verification",
},
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
accessType: "offline",
prompt: "consent",
mapProfileToUser(profile) {
return {
...profile,
providerId: "google",
};
},
},
},
plugins: [
adminPlugin({
defaultRole: "client",
ac: ac,
roles: {
admin,
superadmin,
client,
},
adminRoles: ["superadmin", "admin"],
}),
magicLink({
sendMagicLink: async ({ email, token, url }, request) => {
await sendVerificationRequest({
identifier: email,
url,
provider: {
from: process.env.NEXT_PUBLIC_RESEND_NO_REPLY || "",
apiKey:
process.env.RESEND_FULL_ACCESS_API_KEY || "api_key_placeholder",
},
});
},
}),
genericOAuth({
config: [
{
providerId: "microsoft-entra-id-fgta",
clientId: process.env.FGTA_AUTH_MICROSOFT_ENTRA_ID_ID as string,
clientSecret: process.env
.FGTA_AUTH_MICROSOFT_ENTRA_ID_SECRET as string,
discoveryUrl: `/${process.env.FGTA_AUTH_MICROSOFT_ENTRA_ID_TENANT_ID}/v2.0/.well-known/openid-configuration`,
redirectURI: `${process.env.HOSTNAME_FGTA || "http://localhost:3000"}/api/auth/oauth2/callback/microsoft-entra-id-fgta`,
responseType: "code",
prompt: "select_account",
scopes: ["offline_access", "openid", "profile", "email", "Mail.Send"],
mapProfileToUser(profile) {
return {
...profile,
providerId: "microsoft-entra-id-fgta",
};
},
},
{
providerId: "microsoft-entra-id",
clientId: process.env.AUTH_MICROSOFT_ENTRA_ID_ID as string,
clientSecret: process.env.AUTH_MICROSOFT_ENTRA_ID_SECRET as string,
discoveryUrl: `.0/.well-known/openid-configuration`,
redirectURI: `${baseURL}/api/auth/oauth2/callback/microsoft-entra-id`,
responseType: "code",
prompt: "select_account",
scopes: ["offline_access", "openid", "profile", "email", "Mail.Send"],
mapProfileToUser(profile) {
return {
...profile,
providerId: "microsoft-entra-id",
};
},
},
// Add more providers as needed
],
}),
],
} satisfies BetterAuthOptions;
.....
Note : the microsoft-entra-id-fgta works but not the microsoft
How can I solve this ? Does anyone did get this error ?
本文标签: authenticationBetterauthI can39t connect to Microsoft with generic OAuth providerStack Overflow
版权声明:本文标题:authentication - Better-auth : I can't connect to Microsoft with generic OAuth provider - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744940649a2633462.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论