Fix logging into Github. Add setting default scope even if it not set in config file.

This commit is contained in:
Alexander Simonov 2015-07-12 01:08:04 +03:00
parent 44ec2c3064
commit 9652875129
No known key found for this signature in database
GPG key ID: 5CCFFED829314C35
3 changed files with 13 additions and 1 deletions

View file

@ -231,6 +231,11 @@ func (g *GitHub) Hook(r *http.Request) (*common.Hook, error) {
}
}
// return default scope for GitHub
func (g *GitHub) Scope() string {
return DefaultScope
}
// push parses a hook with event type `push` and returns
// the commit data.
func (g *GitHub) push(r *http.Request) (*common.Hook, error) {

View file

@ -44,4 +44,7 @@ type Remote interface {
// Hook parses the post-commit hook from the Request body
// and returns the required data in a standard format.
Hook(r *http.Request) (*common.Hook, error)
// Default scope for remote
Scope() string
}

View file

@ -134,10 +134,14 @@ func getLoginOauth2(c *gin.Context) {
var settings = ToSettings(c)
var remote = ToRemote(c)
var scope = strings.Join(settings.Auth.Scope, ",")
if scope == "" {
scope = remote.Scope()
}
var config = &oauth2.Config{
ClientId: settings.Auth.Client,
ClientSecret: settings.Auth.Secret,
Scope: strings.Join(settings.Auth.Scope, ","),
Scope: scope,
AuthURL: settings.Auth.Authorize,
TokenURL: settings.Auth.AccessToken,
RedirectURL: fmt.Sprintf("%s/authorize", httputil.GetURL(c.Request)),