fastify / fastify/help

@fastify/oauth2 - Is it possible to request an additional scope programmatically for oAuth Github

Open
#900 7 comments 3 reactions 0 assignees View on GitHub
help wanted
Dominant language
No language data
Stars
68
Forks
8
Avg merge
11h 2m
Merged PRs (30d)
2

Description

Hey folks. I'm using `@fastify/oauth2` and it works flawlessly for many months now. I'd like to implement a feature in the platform I'm building, where our users could sync their public github repositories with their profiles.

Whatsoever, my fastify/oauth2 by default is configured with only 2 scopes that I really need for authentication:

```js
await app.register(oAuth2, {
name: GH_OAUTH_NAME,
scope: "user:email read:user",
credentials: {
client: {
id: process.env.GH_CLIENT_ID,
secret: process.env.GH_CLIENT_SECRET,
},
auth: oAuth2.GITHUB_CONFIGURATION,
},

startRedirectPath: "/auth/github/auth",
callbackUri: process.env.GH_CALLBACK_URL,
});
```

As you can see, I only request a user email and profile when users are authenticating. Whatsoever, I'd like to request a `repo` scope only if the users actually decide to sync their repositories. In simple words, I don't want to ask users for `repo` scope when they are logging in, as I don't know if they will ever want to sync the actual repositories.

So the question is, is it possible to request this additional scope when requesting a new token using some of the methods from the library. I've checked the types of all the existing methods, and it doesn't seem like it. In simple words, when users in my platform click "Sync repositories", I'd like to invoke an oauth flow where I only request a `repo` scope to perform that action.

Thanks in advance,
Alex

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.