Inconsistent name field value accross oauth provider #257

Closed
opened 2026-03-13 07:39:58 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @nayzflux on GitHub (Nov 21, 2024).

Describe the bug
When using Microsoft Oauth the name field for the user is constructed by concatenated Lastname + Firstname however when using other provider like Google its Firstname then Lastname

To Reproduce

  1. Setup Microsoft oauth
  2. Sign up using Microsoft
  3. See the name field

Expected behavior
Name field should be constructed in a consistent way across provider, or the library should provider firstname and lastname field to match provider response.

Desktop (please complete the following information):

  • OS: Windows
  • Browser: Firefox
Originally created by @nayzflux on GitHub (Nov 21, 2024). **Describe the bug** When using Microsoft Oauth the name field for the user is constructed by concatenated Lastname + Firstname however when using other provider like Google its Firstname then Lastname **To Reproduce** 1. Setup Microsoft oauth 2. Sign up using Microsoft 3. See the name field **Expected behavior** Name field should be constructed in a consistent way across provider, or the library should provider firstname and lastname field to match provider response. **Desktop (please complete the following information):** - OS: Windows - Browser: Firefox
Author
Owner

@Bekacru commented on GitHub (Nov 21, 2024):

For both providers you mentioned and I think for almost all of them, we don’t combine the name from two values. We simply use the name value provided by the provider.

@Bekacru commented on GitHub (Nov 21, 2024): For both providers you mentioned and I think for almost all of them, we don’t combine the name from two values. We simply use the name value provided by the provider.
Author
Owner

@avanderbergh commented on GitHub (Nov 22, 2024):

Yeah, can confirm here

import { parseJWT } from "oslo/jwt";

//...

const user = parseJWT(token.idToken)?.payload as MicrosoftEntraIDProfile;

//...

return {
		user: {
			id: user.sub,
			name: user.name,
			email: user.email,
			image: user.picture,
			emailVerified: true,
		},
		data: user,
};
@avanderbergh commented on GitHub (Nov 22, 2024): Yeah, can confirm [here](https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/social-providers/microsoft-entra-id.ts#L66) ```typescript import { parseJWT } from "oslo/jwt"; //... const user = parseJWT(token.idToken)?.payload as MicrosoftEntraIDProfile; //... return { user: { id: user.sub, name: user.name, email: user.email, image: user.picture, emailVerified: true, }, data: user, }; ```
Author
Owner

@nayzflux commented on GitHub (Nov 22, 2024):

Ok thanks you for your reply, is there any possibilities that i could use the firstname and lastname value returned by the provider?

@nayzflux commented on GitHub (Nov 22, 2024): Ok thanks you for your reply, is there any possibilities that i could use the firstname and lastname value returned by the provider?
Author
Owner

@avanderbergh commented on GitHub (Nov 22, 2024):

It should be possible to do that.

here is the token:

{
    "sub": "OLu859SGc2Sr9ZsqbkG-QbeLgJlb41KcdiPoLYNpSFA",
    "name": "Mikah Ollenburg", // all names require the “profile” scope.
    "family_name": " Ollenburg",
    "given_name": "Mikah",
    "picture": "https://graph.microsoft.com/v1.0/me/photo/$value",
    "email": "mikoll@contoso.com" // requires the “email” scope.
}
@avanderbergh commented on GitHub (Nov 22, 2024): It should be possible to do that. [here](https://learn.microsoft.com/en-us/entra/identity-platform/userinfo) is the token: ```json { "sub": "OLu859SGc2Sr9ZsqbkG-QbeLgJlb41KcdiPoLYNpSFA", "name": "Mikah Ollenburg", // all names require the “profile” scope. "family_name": " Ollenburg", "given_name": "Mikah", "picture": "https://graph.microsoft.com/v1.0/me/photo/$value", "email": "mikoll@contoso.com" // requires the “email” scope. } ```
Author
Owner

@nayzflux commented on GitHub (Nov 27, 2024):

Resolved thanks for help

@nayzflux commented on GitHub (Nov 27, 2024): Resolved thanks for help
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#257