Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAuth User Data Should be included in the success value object #94

Open
SOG-web opened this issue Dec 19, 2024 · 8 comments
Open

OAuth User Data Should be included in the success value object #94

SOG-web opened this issue Dec 19, 2024 · 8 comments

Comments

@SOG-web
Copy link

SOG-web commented Dec 19, 2024

I want to suggest we add some basic user info on the oauth provider

at least most people would need the user email, name, id, firstname and lastname

This will make it more easy to adopt for oauth, if anybody is having a more advance use case they can always use the tokens to do that

@thdxr

@SOG-web
Copy link
Author

SOG-web commented Dec 19, 2024

Also I think there is an error with scopes, only one of the scope in the array is getting picked

github: GithubAdapter({
      clientID: process.env.GITHUB_CLIENT_ID!,
      clientSecret: process.env.GITHUB_CLIENT_SECRET!,
      scopes: ["user:email", "profile"],
    }),
    ```

Response of oauth (value.tokenset.raw)
```ts
{
  access_token: "gggg",
  token_type: "bearer",
  scope: "user:email",
}

@SOG-web
Copy link
Author

SOG-web commented Dec 19, 2024

Am using this currently

} else if (value.provider === "github") {
      const githubUserResponse = await fetch("https://api.github.com/user", {
        headers: {
          Authorization: `Bearer ${value.tokenset.access}`,
        },
      });


      const githubUser: GitHubUser = await githubUserResponse.json();
      }
      

Doing this for all oauth provider will be very tedious since all I need is the email and the name from any oauth provider

or we could just dump the data on value.extra, so from there anyone can pick what they need

@Cmion
Copy link

Cmion commented Dec 20, 2024

This might be tricky tho, since we may need to account for each scopes. For instance do we want to get the user's full profile with

const response = await fetch("https://api.github.com/user", {
	headers: {
		Authorization: `Bearer ${value.tokenset.access}`
	}
});
const user = await response.json();

or just their emails with scope(user:email)

const response = await fetch("https://api.github.com/user/emails", {
	headers: {
		Authorization: `Bearer ${value.tokenset.access}`
	}
});
const emails = await response.json();

@SOG-web
Copy link
Author

SOG-web commented Dec 20, 2024

This might be tricky tho, since we may need to account for each scopes. For instance do we want to get the user's full profile with

const response = await fetch("https://api.github.com/user", {
	headers: {
		Authorization: `Bearer ${value.tokenset.access}`
	}
});
const user = await response.json();

or just their emails with scope(user:email)

const response = await fetch("https://api.github.com/user/emails", {
	headers: {
		Authorization: `Bearer ${value.tokenset.access}`
	}
});
const emails = await response.json();

I think just getting the user profile should be enough for most use casess

@SteakFisher
Copy link

Wouldn't forwarding along the access tokens returned by each provider as part of the subjects object suffice?

@thdxr
Copy link
Contributor

thdxr commented Dec 20, 2024

the challenge here is there is no consistent spec for just oauth2 to get userinfo - there is for those who implement OIDC

i think having to add a fetch in your success handler is a bit annoying but ultimately not a big deal so would probably just ask people to do that instead of assuming what you want to do

@SOG-web
Copy link
Author

SOG-web commented Dec 20, 2024

the challenge here is there is no consistent spec for just oauth2 to get userinfo - there is for those who implement OIDC

i think having to add a fetch in your success handler is a bit annoying but ultimately not a big deal so would probably just ask people to do that instead of assuming what you want to do

Hmm, I get you know. What if i create a package that does just the fetching of the user profile then maybe we can just give an optional way for people to inject it into the oauth process instead of doing it on success.

That will make it more cleaner

@SOG-web
Copy link
Author

SOG-web commented Dec 20, 2024

Also I think there is way the go community are handling it, I can do a little digging

Because on go side the user profile is been returned for all the oauth providers they support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants