1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-26 18:21:01 +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,