add provider prefix to ID

This commit is contained in:
Eugene
2017-12-22 15:05:06 -06:00
parent 1ee5346c4f
commit 8196c227c3
3 changed files with 6 additions and 4 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ var opts struct {
GithubCSEC string `long:"github-csec" env:"REMARK_GITHUB_CSEC" description:"Github OAuth client secret"`
Admins []string `long:"admin" env:"ADMIN" default:"umputun@gmail.com" description:"admin(s) names" env-delim:","`
DevMode bool `long:"dev" env:"DEV" description:"dev mode mode"`
DevMode bool `long:"dev" env:"DEV" description:"development mode, no auth enforced"`
Dbg bool `long:"dbg" env:"DEBUG" description:"debug mode"`
}
+2 -2
View File
@@ -56,7 +56,7 @@ func initProvider(p Params, provider Provider) *Provider {
return &provider
}
// LoginHandler - GET /login/github?from=http://radio-t.com
// LoginHandler - GET /login/{provider}?from=redirect-back-url
func (p Provider) LoginHandler(w http.ResponseWriter, r *http.Request) {
// make state (random) and store in session
@@ -83,7 +83,7 @@ func (p Provider) LoginHandler(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, p.conf.AuthCodeURL(state), http.StatusTemporaryRedirect)
}
// AuthHandler is redirect url. Should check state to prevent CSRF.
// AuthHandler fills user info and redirects to "from" url
func (p Provider) AuthHandler(w http.ResponseWriter, r *http.Request) {
session, err := p.Get(r, "remark")
if err != nil {
+3 -1
View File
@@ -20,14 +20,15 @@ func NewGoogle(p Params) *Provider {
FilesystemStore: p.SessionStore,
MapUser: func(data map[string]interface{}) store.User {
userInfo := store.User{
Name: data["name"].(string),
ID: data["email"].(string),
Name: data["name"].(string),
Picture: data["picture"].(string),
Profile: data["profile"].(string),
}
if userInfo.Name == "" {
userInfo.Name = strings.Split(userInfo.ID, "@")[0]
}
userInfo.ID = "google_" + userInfo.ID
return userInfo
},
})
@@ -52,6 +53,7 @@ func NewGithub(p Params) *Provider {
if userInfo.Name == "" {
userInfo.Name = userInfo.ID
}
userInfo.ID = "github_" + userInfo.ID
return userInfo
},
})