Phil
Phil
BABetter Auth
Created by Phil on 4/28/2025 in #help
How to link Generic OAuth to existing user
Ah, I figured it out: it requires a combination of setting allowDifferentEmails: true and using genericAuthClient.oauth2.link instead of genericAuthClient.signIn.oauth2.
3 replies
BABetter Auth
Created by Phil on 4/28/2025 in #help
How to link Generic OAuth to existing user
Here is my Generic OAuth config if it helps:
providerId: "nylas",
clientId: process.env.NEXT_PUBLIC_NYLAS_CLIENT_ID!,
clientSecret: process.env.NEXT_PUBLIC_NYLAS_CLIENT_SECRET!,
authorizationUrl: `https://${process.env.NEXT_PUBLIC_NYLAS_API_URI}/v3/connect/auth`,
tokenUrl: `https://${process.env.NEXT_PUBLIC_NYLAS_API_URI}/v3/connect/token`,
userInfoUrl: `https://${process.env.NEXT_PUBLIC_NYLAS_API_URI}/v3/grants/me`,
scopes: ['https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/gmail.modify', 'https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/gmail.labels', 'https://www.googleapis.com/auth/contacts'],
getUserInfo: async ({ accessToken }) => {
const response = await fetch(
`https://${process.env.NEXT_PUBLIC_NYLAS_API_URI}/v3/grants/me`,
{ headers: { Authorization: `Bearer ${accessToken}` } }
);
const userData = await response.json();
return {
id: userData.data.id,
provider: userData.data.provider,
email: userData.data.email,
emailVerified: true,
name: userData.data.name,
};
},
providerId: "nylas",
clientId: process.env.NEXT_PUBLIC_NYLAS_CLIENT_ID!,
clientSecret: process.env.NEXT_PUBLIC_NYLAS_CLIENT_SECRET!,
authorizationUrl: `https://${process.env.NEXT_PUBLIC_NYLAS_API_URI}/v3/connect/auth`,
tokenUrl: `https://${process.env.NEXT_PUBLIC_NYLAS_API_URI}/v3/connect/token`,
userInfoUrl: `https://${process.env.NEXT_PUBLIC_NYLAS_API_URI}/v3/grants/me`,
scopes: ['https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/gmail.modify', 'https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/gmail.labels', 'https://www.googleapis.com/auth/contacts'],
getUserInfo: async ({ accessToken }) => {
const response = await fetch(
`https://${process.env.NEXT_PUBLIC_NYLAS_API_URI}/v3/grants/me`,
{ headers: { Authorization: `Bearer ${accessToken}` } }
);
const userData = await response.json();
return {
id: userData.data.id,
provider: userData.data.provider,
email: userData.data.email,
emailVerified: true,
name: userData.data.name,
};
},
3 replies
BABetter Auth
Created by Phil on 12/28/2024 in #help
Possible to pass an additional OAuth parameter?
Will do, thanks.
3 replies
BABetter Auth
Created by Phil on 12/27/2024 in #help
Can't get user data mapped properly
Ah Ok, thanks, yeah I should have looked at the actual value of tokens that gets passed into that function. When I don't include any custom getUserInfo function at all, the user data structure I posted above gets returned, so I assumed it was also coming into getUserInfo. But it's not - tokens just contains the actual OAuth token data itself. So like you said, I guess I'll need to fetch the user info inside the function using the token.
9 replies
BABetter Auth
Created by Phil on 12/27/2024 in #help
Can't get user data mapped properly
Yes the redirect uri is set and I'm pretty sure that's working because Asana is properly returning the structure I posted above which is accurate for my currently-logged-in Asana user. Well I've tried a lot of different things for getUserInfo - here's one of the simpler ones:
const getUserInfo = async (tokens: OAuth2Tokens): Promise<User | null> => {
const userData = tokens.user; // assuming the data structure is passed in via tokens.user

if (!userData?.data) {
return null;
}

return {
id: userData.data.gid,
emailVerified: userData.data.email,
email: userData.data.email,
name: userData.data.name,
image: userData.data.photo?.image_128x128,
data: userData.data
};
};
const getUserInfo = async (tokens: OAuth2Tokens): Promise<User | null> => {
const userData = tokens.user; // assuming the data structure is passed in via tokens.user

if (!userData?.data) {
return null;
}

return {
id: userData.data.gid,
emailVerified: userData.data.email,
email: userData.data.email,
name: userData.data.name,
image: userData.data.photo?.image_128x128,
data: userData.data
};
};
9 replies
BABetter Auth
Created by Phil on 12/27/2024 in #help
Can't get user data mapped properly
I've had various bits of code in there for both getUserInfo and mapProfileToUser but nothing has worked.
9 replies
BABetter Auth
Created by Phil on 12/27/2024 in #help
Can't get user data mapped properly
Sure:
genericOAuth({
config: [
{
providerId: "asana",
clientId: "643xxxxxxxx4856",
clientSecret: "90e98daxxxxxxxxxxxxxxx6ccab2158d",
authorizationUrl: 'https://app.asana.com/-/oauth_authorize',
tokenUrl: 'https://app.asana.com/-/oauth_token',
userInfoUrl: 'https://app.asana.com/api/1.0/users/me',
pkce: true,
// discoveryUrl: "https://auth.example.com/.well-known/openid-configuration",
// ... other config options
},
]
}),
genericOAuth({
config: [
{
providerId: "asana",
clientId: "643xxxxxxxx4856",
clientSecret: "90e98daxxxxxxxxxxxxxxx6ccab2158d",
authorizationUrl: 'https://app.asana.com/-/oauth_authorize',
tokenUrl: 'https://app.asana.com/-/oauth_token',
userInfoUrl: 'https://app.asana.com/api/1.0/users/me',
pkce: true,
// discoveryUrl: "https://auth.example.com/.well-known/openid-configuration",
// ... other config options
},
]
}),
9 replies