1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-09-15 18:57:04 +00:00

Remove extra column from users table (HSTORE field)

Migrated key/value pairs to specific columns.
This commit is contained in:
Frédéric Guillot 2020-12-21 21:14:10 -08:00 committed by fguillot
parent ae74f94655
commit 83f3ccab0e
19 changed files with 256 additions and 141 deletions

View file

@ -9,6 +9,8 @@ import (
"encoding/json"
"fmt"
"miniflux.app/model"
"golang.org/x/oauth2"
)
@ -23,15 +25,15 @@ type googleProvider struct {
redirectURL string
}
func (g googleProvider) GetUserExtraKey() string {
func (g *googleProvider) GetUserExtraKey() string {
return "google_id"
}
func (g googleProvider) GetRedirectURL(state string) string {
func (g *googleProvider) GetRedirectURL(state string) string {
return g.config().AuthCodeURL(state)
}
func (g googleProvider) GetProfile(ctx context.Context, code string) (*Profile, error) {
func (g *googleProvider) GetProfile(ctx context.Context, code string) (*Profile, error) {
conf := g.config()
token, err := conf.Exchange(ctx, code)
if err != nil {
@ -48,14 +50,22 @@ func (g googleProvider) GetProfile(ctx context.Context, code string) (*Profile,
var user googleProfile
decoder := json.NewDecoder(resp.Body)
if err := decoder.Decode(&user); err != nil {
return nil, fmt.Errorf("unable to unserialize google profile: %v", err)
return nil, fmt.Errorf("oauth2: unable to unserialize google profile: %v", err)
}
profile := &Profile{Key: g.GetUserExtraKey(), ID: user.Sub, Username: user.Email}
return profile, nil
}
func (g googleProvider) config() *oauth2.Config {
func (g *googleProvider) PopulateUserWithProfileID(user *model.User, profile *Profile) {
user.GoogleID = profile.ID
}
func (g *googleProvider) UnsetUserProfileID(user *model.User) {
user.GoogleID = ""
}
func (g *googleProvider) config() *oauth2.Config {
return &oauth2.Config{
RedirectURL: g.redirectURL,
ClientID: g.clientID,

View file

@ -7,6 +7,7 @@ package oauth2 // import "miniflux.app/oauth2"
import (
"context"
"errors"
"miniflux.app/logger"
)
@ -15,8 +16,8 @@ type Manager struct {
providers map[string]Provider
}
// Provider returns the given provider.
func (m *Manager) Provider(name string) (Provider, error) {
// FindProvider returns the given provider.
func (m *Manager) FindProvider(name string) (Provider, error) {
if provider, found := m.providers[name]; found {
return provider, nil
}

View file

@ -6,6 +6,9 @@ package oauth2 // import "miniflux.app/oauth2"
import (
"context"
"miniflux.app/model"
"github.com/coreos/go-oidc"
"golang.org/x/oauth2"
)
@ -17,15 +20,15 @@ type oidcProvider struct {
provider *oidc.Provider
}
func (o oidcProvider) GetUserExtraKey() string {
return "oidc_id" // FIXME? add extra options key to allow multiple OIDC providers each with their own extra key?
func (o *oidcProvider) GetUserExtraKey() string {
return "openid_connect_id"
}
func (o oidcProvider) GetRedirectURL(state string) string {
func (o *oidcProvider) GetRedirectURL(state string) string {
return o.config().AuthCodeURL(state)
}
func (o oidcProvider) GetProfile(ctx context.Context, code string) (*Profile, error) {
func (o *oidcProvider) GetProfile(ctx context.Context, code string) (*Profile, error) {
conf := o.config()
token, err := conf.Exchange(ctx, code)
if err != nil {
@ -41,7 +44,15 @@ func (o oidcProvider) GetProfile(ctx context.Context, code string) (*Profile, er
return profile, nil
}
func (o oidcProvider) config() *oauth2.Config {
func (o *oidcProvider) PopulateUserWithProfileID(user *model.User, profile *Profile) {
user.OpenIDConnectID = profile.ID
}
func (o *oidcProvider) UnsetUserProfileID(user *model.User) {
user.OpenIDConnectID = ""
}
func (o *oidcProvider) config() *oauth2.Config {
return &oauth2.Config{
RedirectURL: o.redirectURL,
ClientID: o.clientID,

View file

@ -3,11 +3,18 @@
// license that can be found in the LICENSE file.
package oauth2 // import "miniflux.app/oauth2"
import "context"
import (
"context"
"miniflux.app/model"
)
// Provider is an interface for OAuth2 providers.
type Provider interface {
GetUserExtraKey() string
GetRedirectURL(state string) string
GetProfile(ctx context.Context, code string) (*Profile, error)
PopulateUserWithProfileID(user *model.User, profile *Profile)
UnsetUserProfileID(user *model.User)
}