How to get user info? #3526
-
Question 💬calling user info endpoint directly(identity server 4 or google) with the access token is giving me the correct user info but how am I supposed to get it with next-auth? // user info example
{
name: 'name',
picture: 'picture',
sub: '8ec2516a-ee0a-4f7a-80f0-77476752f6a1'
} I've already read all the documentation and issues. How to reproduce ☕️export default NextAuth({
providers: [
IdentityServer4Provider({
id: 'identity-server4',
name: 'IdentityServer4',
issuer: 'https://demo.identityserver.io',
clientId: 'interactive.public',
clientSecret: 'secret',
authorization: { params: { scope: 'openid profile' } },
}),
]
}); Contributing 🙌🏽No, I am afraid I cannot help regarding this |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
@balazsorban44 |
Beta Was this translation helpful? Give feedback.
-
working code for custom user info. identity server 4 import axios from 'axios';
import NextAuth from 'next-auth';
import IdentityServer4Provider from 'next-auth/providers/identity-server4';
export default NextAuth({
providers: [
IdentityServer4Provider({
id: 'identity-server4',
name: 'IdentityServer4',
issuer: 'https://demo.identityserver.io',
clientId: 'interactive.public',
clientSecret: 'secret',
userinfo: {
url: 'https://demo.identityserver.io/connect/userinfo',
async request(context) {
const res = await axios.get('https://demo.identityserver.io/connect/userinfo', {
headers: {
Authorization: `Bearer ${context.tokens.access_token}`,
},
});
return res.data;
},
},
profile: (profile) => {
return {
id: profile.sub,
name: profile.name,
picture: profile.picture,
};
},
authorization: { params: { scope: 'openid profile' } },
idToken: true,
}),
],
callbacks: {
async session({ session, user, token }) {
session.user = token.user;
return session;
},
async jwt({ token, user, account, profile, isNewUser }) {
if (profile) {
token.user = profile;
}
return token;
},
},
}); |
Beta Was this translation helpful? Give feedback.
working code for custom user info. identity server 4