當前位置: 首頁>>代碼示例>>Golang>>正文


Golang AuthorizationParams.Note方法代碼示例

本文整理匯總了Golang中github.com/octokit/go-octokit/octokit.AuthorizationParams.Note方法的典型用法代碼示例。如果您正苦於以下問題:Golang AuthorizationParams.Note方法的具體用法?Golang AuthorizationParams.Note怎麽用?Golang AuthorizationParams.Note使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/octokit/go-octokit/octokit.AuthorizationParams的用法示例。


在下文中一共展示了AuthorizationParams.Note方法的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
}
開發者ID:aergonaut,項目名稱:hub,代碼行數:52,代碼來源:client.go

示例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
}
開發者ID:johnbellone,項目名稱:gh,代碼行數:38,代碼來源:github.go


注:本文中的github.com/octokit/go-octokit/octokit.AuthorizationParams.Note方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。