OAuth2 Provider #31
-
If I understand your documentation correctly, the provider parameter in the profile is supposed to determine the path to route to in order to run that provider configuration. For example: new OAuth2Provider({
scope: "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email",
params: { grant_type: "authorization_code" },
accessTokenUrl: "https://accounts.google.com/o/oauth2/token",
requestTokenUrl: "https://accounts.google.com/o/oauth2/auth",
authorizationUrl: "https://accounts.google.com/o/oauth2/auth?response_type=code",
profileUrl: "https://www.googleapis.com/oauth2/v1/userinfo?alt=json",
profile (profile) {
return { ...profile, provider: "custom" };
},
clientId: "",
clientSecret: ""
}) Should allow me to route to /api/auth/signin/custom and it will perform the custom authentication (google in this case). Correct? I am getting this error:
Did I miss something in the docs? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Sorry! That's a bit confusing currently in the demo app I use the export const appAuth = new SvelteKitAuth({
callbacks: {
jwt(token, profile) {
if (profile?.provider) {
const { provider, ...account } = profile; // profile returned by profile() callback
token = {
...token,
user: {
...(token.user ?? {}),
connections: { ...(token.user?.connections ?? {}), [provider]: account },
},
};
}
return token;
},
}); SvelteKitAuth internally uses the new OAuth2Provider({
id: "custom",
scope:
"https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email",
params: { grant_type: "authorization_code" },
accessTokenUrl: "https://accounts.google.com/o/oauth2/token",
requestTokenUrl: "https://accounts.google.com/o/oauth2/auth",
authorizationUrl:
"https://accounts.google.com/o/oauth2/auth?response_type=code",
profileUrl: "https://www.googleapis.com/oauth2/v1/userinfo?alt=json",
profile(profile) {
return { ...profile, provider: "custom" };
},
clientId: "",
clientSecret: "",
}); This will map the routes to |
Beta Was this translation helpful? Give feedback.
-
Brilliant! I knew it was something simple I was missing. Thanks. |
Beta Was this translation helpful? Give feedback.
Sorry! That's a bit confusing currently in the demo app I use the
profile()
callback simply to remap the profile and add theprovider
information for later use in thejwt()
callback. As you can see, I'm able to append as many connections as I want then allowing me to display the connections in the UI: