mirror of
https://github.com/miniflux/v2.git
synced 2025-08-01 17:38:37 +00:00
Add OAuth2 PKCE support
This commit is contained in:
parent
fa1148915e
commit
ff5d391701
12 changed files with 126 additions and 68 deletions
|
@ -19,17 +19,32 @@ type oidcProvider struct {
|
|||
provider *oidc.Provider
|
||||
}
|
||||
|
||||
func NewOidcProvider(ctx context.Context, clientID, clientSecret, redirectURL, discoveryEndpoint string) (*oidcProvider, error) {
|
||||
provider, err := oidc.NewProvider(ctx, discoveryEndpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &oidcProvider{clientID: clientID, clientSecret: clientSecret, redirectURL: redirectURL, provider: provider}, nil
|
||||
}
|
||||
|
||||
func (o *oidcProvider) GetUserExtraKey() string {
|
||||
return "openid_connect_id"
|
||||
}
|
||||
|
||||
func (o *oidcProvider) GetRedirectURL(state string) string {
|
||||
return o.config().AuthCodeURL(state)
|
||||
func (o *oidcProvider) GetConfig() *oauth2.Config {
|
||||
return &oauth2.Config{
|
||||
RedirectURL: o.redirectURL,
|
||||
ClientID: o.clientID,
|
||||
ClientSecret: o.clientSecret,
|
||||
Scopes: []string{"openid", "email"},
|
||||
Endpoint: o.provider.Endpoint(),
|
||||
}
|
||||
}
|
||||
|
||||
func (o *oidcProvider) GetProfile(ctx context.Context, code string) (*Profile, error) {
|
||||
conf := o.config()
|
||||
token, err := conf.Exchange(ctx, code)
|
||||
func (o *oidcProvider) GetProfile(ctx context.Context, code, codeVerifier string) (*Profile, error) {
|
||||
conf := o.GetConfig()
|
||||
token, err := conf.Exchange(ctx, code, oauth2.SetAuthURLParam("code_verifier", codeVerifier))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -54,22 +69,3 @@ func (o *oidcProvider) PopulateUserWithProfileID(user *model.User, profile *Prof
|
|||
func (o *oidcProvider) UnsetUserProfileID(user *model.User) {
|
||||
user.OpenIDConnectID = ""
|
||||
}
|
||||
|
||||
func (o *oidcProvider) config() *oauth2.Config {
|
||||
return &oauth2.Config{
|
||||
RedirectURL: o.redirectURL,
|
||||
ClientID: o.clientID,
|
||||
ClientSecret: o.clientSecret,
|
||||
Scopes: []string{"openid", "email"},
|
||||
Endpoint: o.provider.Endpoint(),
|
||||
}
|
||||
}
|
||||
|
||||
func newOidcProvider(ctx context.Context, clientID, clientSecret, redirectURL, discoveryEndpoint string) (*oidcProvider, error) {
|
||||
provider, err := oidc.NewProvider(ctx, discoveryEndpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &oidcProvider{clientID: clientID, clientSecret: clientSecret, redirectURL: redirectURL, provider: provider}, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue