本文整理匯總了Golang中github.com/octokit/go-octokit/octokit.AuthorizationParams類的典型用法代碼示例。如果您正苦於以下問題:Golang AuthorizationParams類的具體用法?Golang AuthorizationParams怎麽用?Golang AuthorizationParams使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了AuthorizationParams類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: FindOrCreateToken
func (client *Client) FindOrCreateToken(user, password, twoFactorCode string) (token string, err error) {
authUrl, e := octokit.AuthorizationsURL.Expand(nil)
if e != nil {
err = &AuthError{e}
return
}
basicAuth := octokit.BasicAuth{
Login: user,
Password: password,
OneTimePassword: twoFactorCode,
}
c := client.newOctokitClient(basicAuth)
authsService := c.Authorizations(client.requestURL(authUrl))
authParam := octokit.AuthorizationParams{
Scopes: []string{"repo"},
NoteURL: OAuthAppURL,
}
count := 1
for {
note, e := authTokenNote(count)
if e != nil {
err = e
return
}
authParam.Note = note
auth, result := authsService.Create(authParam)
if !result.HasError() {
token = auth.Token
break
}
authErr := &AuthError{result.Err}
if authErr.IsDuplicatedTokenError() {
if count >= 9 {
err = authErr
break
} else {
count++
continue
}
} else {
err = authErr
break
}
}
return
}
示例2: findOrCreateToken
func findOrCreateToken(user, password, twoFactorCode string) (token string, err error) {
basicAuth := octokit.BasicAuth{Login: user, Password: password, OneTimePassword: twoFactorCode}
client := octokit.NewClient(basicAuth)
authsService, err := client.Authorizations(nil, nil)
if err != nil {
return
}
auths, result := authsService.GetAll()
if result.HasError() {
err = result.Err
return
}
for _, auth := range auths {
if auth.NoteURL == OAuthAppURL {
token = auth.Token
break
}
}
if token == "" {
authParam := octokit.AuthorizationParams{}
authParam.Scopes = append(authParam.Scopes, "repo")
authParam.Note = "gh"
authParam.NoteURL = OAuthAppURL
auth, result := authsService.Create(authParam)
if result.HasError() {
err = result.Err
return
}
token = auth.Token
}
return
}