mirror of
https://github.com/miniflux/v2.git
synced 2025-08-01 17:38:37 +00:00
Prevent empty username when using the OIDC integration
This commit is contained in:
parent
36f013670e
commit
ab0c4ec0f5
2 changed files with 16 additions and 5 deletions
|
@ -5,6 +5,8 @@ package oauth2 // import "miniflux.app/v2/internal/oauth2"
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"miniflux.app/v2/internal/model"
|
||||
|
||||
|
@ -12,6 +14,10 @@ import (
|
|||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrEmptyUsername = errors.New("oidc: username is empty")
|
||||
)
|
||||
|
||||
type oidcProvider struct {
|
||||
clientID string
|
||||
clientSecret string
|
||||
|
@ -46,15 +52,20 @@ func (o *oidcProvider) GetProfile(ctx context.Context, code, codeVerifier string
|
|||
conf := o.GetConfig()
|
||||
token, err := conf.Exchange(ctx, code, oauth2.SetAuthURLParam("code_verifier", codeVerifier))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf(`oidc: failed to exchange token: %w`, err)
|
||||
}
|
||||
|
||||
userInfo, err := o.provider.UserInfo(ctx, oauth2.StaticTokenSource(token))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf(`oidc: failed to get user info: %w`, err)
|
||||
}
|
||||
|
||||
profile := &Profile{Key: o.GetUserExtraKey(), ID: userInfo.Subject, Username: userInfo.Email}
|
||||
|
||||
if profile.Username == "" {
|
||||
return nil, ErrEmptyUsername
|
||||
}
|
||||
|
||||
return profile, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue