Error With Azure Active Directory
Answered
Cinnamon posted this in #help-forum
CinnamonOP
When another user than me tries to login, this message is displayed on screen
Answered by Cinnamon
I found the problem. Instead of using the tenant id in the
.env.local, I used "common". Like this:AZURE_AD_CLIENT_ID=<id>
AZURE_AD_CLIENT_SECRET=<id>
#AZURE_AD_TENANT_ID=<id>
AZURE_AD_TENANT_ID=common7 Replies
CinnamonOP
I'm using NextAuth (latest version). This is my code for the provider:
import AzureADProvider from "next-auth/providers/azure-ad";
export const authOptions = {
providers: [
AzureADProvider({
clientId: process.env.AZURE_AD_CLIENT_ID as string,
clientSecret: process.env.AZURE_AD_CLIENT_SECRET as string,
tenantId: process.env.AZURE_AD_TENANT_ID,
httpOptions: { timeout: 10000 },
})
],
callbacks: {
async jwt({ token, user, account }: { token: any, user: any, account: any }) {
if (account && user) {
return {
accessToken: account.id_token,
accessTokenExpires: account?.expires_at
? account.expires_at * 1000
: 0,
refreshToken: account.refresh_token,
user,
};
}
if (Date.now() < token.accessTokenExpires - 100000 || 0) {
return token;
}
},
async session({ session, token }: { session: any, token: any }) {
if (session) {
session.user = token.user;
session.error = token.error;
session.accessToken = token.accessToken;
}
return session;
},
},
};The login works on my account (the account who created the app)
Kintamani
Based on the error it seems like it has more to do with azure than next auth
@Kintamani https://learn.microsoft.com/en-us/answers/questions/1193035/how-to-fix-selected-user-account-does-not-exist-in
CinnamonOP
Yes, but I want all my users to be able to log in without me accepting individually each of them
(I want to make a Microsoft) login option
CinnamonOP
I found the problem. Instead of using the tenant id in the
.env.local, I used "common". Like this:AZURE_AD_CLIENT_ID=<id>
AZURE_AD_CLIENT_SECRET=<id>
#AZURE_AD_TENANT_ID=<id>
AZURE_AD_TENANT_ID=commonAnswer