Skip to content

Commit

Permalink
#141 minor formatting fixes for linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bnfinet committed Sep 13, 2019
1 parent b46c917 commit 95be07d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
5 changes: 2 additions & 3 deletions handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,9 @@ func getUserInfo(r *http.Request, user *structs.User, customClaims *structs.Cust
}
ptokens.PAccessToken = providerToken.AccessToken
if cfg.GenOAuth.Provider == cfg.Providers.OpenStax {
client := cfg.OAuthClient.Client(context.TODO(), providerToken)
client := cfg.OAuthClient.Client(context.TODO(), providerToken)
return getUserInfoFromOpenStax(client, user, customClaims, providerToken)
}
}
ptokens.PIdToken = providerToken.Extra("id_token").(string)
log.Debugf("ptokens: %+v", ptokens)

Expand Down Expand Up @@ -569,7 +569,6 @@ func getUserInfoFromOpenID(client *http.Client, user *structs.User, customClaims
return nil
}


func getUserInfoFromOpenStax(client *http.Client, user *structs.User, customClaims *structs.CustomClaims, ptoken *oauth2.Token) (rerr error) {
userinfo, err := client.Get(cfg.GenOAuth.UserInfoURL)
if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions pkg/cfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,13 @@ func Get(key string) string {
// BasicTest just a quick sanity check to see if the config is sound
func BasicTest() error {
if GenOAuth.Provider != Providers.Google &&
GenOAuth.Provider != Providers.GitHub &&
GenOAuth.Provider != Providers.IndieAuth &&
GenOAuth.Provider != Providers.ADFS &&
GenOAuth.Provider != Providers.OIDC &&
GenOAuth.Provider != Providers.OpenStax {
return errors.New("configuration error: Unkown oauth provider: "+ GenOAuth.Provider)
}
GenOAuth.Provider != Providers.GitHub &&
GenOAuth.Provider != Providers.IndieAuth &&
GenOAuth.Provider != Providers.ADFS &&
GenOAuth.Provider != Providers.OIDC &&
GenOAuth.Provider != Providers.OpenStax {
return errors.New("configuration error: Unkown oauth provider: " + GenOAuth.Provider)
}

for _, opt := range RequiredOptions {
if !viper.IsSet(opt) {
Expand Down Expand Up @@ -541,7 +541,7 @@ func SetDefaults() {
setDefaultsADFS()
configureOAuthClient()
} else {
// IndieAuth, OIDC, OpenStax
// IndieAuth, OIDC, OpenStax
configureOAuthClient()
}
}
Expand Down
36 changes: 19 additions & 17 deletions pkg/structs/structs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package structs

// Temporary struct storing custom claims until JWT creation.
// CustomClaims Temporary struct storing custom claims until JWT creation.
type CustomClaims struct {
Claims map[string]interface{}
}
Expand All @@ -27,8 +27,8 @@ type User struct {
// PrepareUserData implement PersonalData interface
func (u *User) PrepareUserData() {
if u.Username == "" {
u.Username = u.Email
}
u.Username = u.Email
}
}

// GoogleUser is a retrieved and authentiacted user from Google.
Expand Down Expand Up @@ -95,29 +95,30 @@ func (u *IndieAuthUser) PrepareUserData() {
u.Username = u.URL
}

// Contact used for OpenStaxUser
type Contact struct {
Type string `json:"type"`
Value string `json:"value"`
Verified bool `json:"is_verified"`
Type string `json:"type"`
Value string `json:"value"`
Verified bool `json:"is_verified"`
}

//OpenStaxUser is a retrieved and authenticated user from OpenStax Accounts
type OpenStaxUser struct {
User
Contacts []Contact `json:"contact_infos"`
User
Contacts []Contact `json:"contact_infos"`
}

// PrepareUserData implement PersonalData interface
func (u *OpenStaxUser) PrepareUserData() {
if u.Email == "" {
// assuming first contact of type "EmailAddress"
for _, c := range u.Contacts {
if c.Type == "EmailAddress" && c.Verified {
u.Email = c.Value
break
}
}
}
if u.Email == "" {
// assuming first contact of type "EmailAddress"
for _, c := range u.Contacts {
if c.Type == "EmailAddress" && c.Verified {
u.Email = c.Value
break
}
}
}
}

// Team has members and provides acess to sites
Expand All @@ -138,6 +139,7 @@ type Site struct {
ID int `json:"id" mapstructure:"id"`
}

// PTokens provider tokens (from the IdP)
type PTokens struct {
PAccessToken string
PIdToken string
Expand Down

0 comments on commit 95be07d

Please sign in to comment.