Merge pull request #1511 from dmcgowan/fix-oauth-cross-repo-push
Fix oauth cross repository push
This commit is contained in:
commit
83b3d93ce3
1 changed files with 9 additions and 5 deletions
|
@ -213,16 +213,18 @@ func (th *tokenHandler) AuthorizeRequest(req *http.Request, params map[string]st
|
||||||
Actions: []string{"pull"},
|
Actions: []string{"pull"},
|
||||||
}.String())
|
}.String())
|
||||||
}
|
}
|
||||||
if err := th.refreshToken(params, additionalScopes...); err != nil {
|
|
||||||
|
token, err := th.getToken(params, additionalScopes...)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", th.tokenCache))
|
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (th *tokenHandler) refreshToken(params map[string]string, additionalScopes ...string) error {
|
func (th *tokenHandler) getToken(params map[string]string, additionalScopes ...string) (string, error) {
|
||||||
th.tokenLock.Lock()
|
th.tokenLock.Lock()
|
||||||
defer th.tokenLock.Unlock()
|
defer th.tokenLock.Unlock()
|
||||||
scopes := make([]string, 0, len(th.scopes)+len(additionalScopes))
|
scopes := make([]string, 0, len(th.scopes)+len(additionalScopes))
|
||||||
|
@ -239,7 +241,7 @@ func (th *tokenHandler) refreshToken(params map[string]string, additionalScopes
|
||||||
if now.After(th.tokenExpiration) || addedScopes {
|
if now.After(th.tokenExpiration) || addedScopes {
|
||||||
token, expiration, err := th.fetchToken(params, scopes)
|
token, expiration, err := th.fetchToken(params, scopes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// do not update cache for added scope tokens
|
// do not update cache for added scope tokens
|
||||||
|
@ -247,9 +249,11 @@ func (th *tokenHandler) refreshToken(params map[string]string, additionalScopes
|
||||||
th.tokenCache = token
|
th.tokenCache = token
|
||||||
th.tokenExpiration = expiration
|
th.tokenExpiration = expiration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return token, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return th.tokenCache, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type postTokenResponse struct {
|
type postTokenResponse struct {
|
||||||
|
|
Loading…
Reference in a new issue