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


Golang oauth.Credentials類代碼示例

本文整理匯總了Golang中github.com/garyburd/go-oauth/oauth.Credentials的典型用法代碼示例。如果您正苦於以下問題:Golang Credentials類的具體用法?Golang Credentials怎麽用?Golang Credentials使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Credentials類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: signQuery

func (bs *BossSearch) signQuery(url string, values *url.Values) {
	cred := oauth.Credentials{}
	cred.Token = bs.Token
	cred.Secret = bs.Secret

	client := oauth.Client{}
	client.SignatureMethod = oauth.HMACSHA1
	client.Credentials = cred

	client.SignForm(nil, "GET", url, *values)
}
開發者ID:ThunApps,項目名稱:YahooBoss,代碼行數:11,代碼來源:yahooboss.go

示例2: handleOauthTwitterCallback

// url: GET /oauthtwittercb?redirect=$redirect
func handleOauthTwitterCallback(w http.ResponseWriter, r *http.Request) {
	//fmt.Printf("handleOauthTwitterCallback()\n")
	redirect := strings.TrimSpace(r.FormValue("redirect"))
	if redirect == "" {
		serveErrorMsg(w, "Missing redirect value for /login")
		return
	}
	tempCred := oauth.Credentials{
		Token: r.FormValue("oauth_token"),
	}
	tempCred.Secret = decodeTwitterTempFromCookie(r)
	if "" == tempCred.Secret {
		http.Error(w, "Error getting temp token secret from cookie, ", 500)
		return
	}
	//fmt.Printf("  tempCred.Secret: %s\n", tempCred.Secret)
	tokenCred, _, err := oauthClient.RequestToken(http.DefaultClient, &tempCred, r.FormValue("oauth_verifier"))
	if err != nil {
		http.Error(w, "Error getting request token, "+err.Error(), 500)
		return
	}

	//fmt.Printf("  tokenCred.Token: %s\n", tokenCred.Token)

	var info map[string]interface{}
	if err := getTwitter(
		tokenCred,
		"https://api.twitter.com/1/account/verify_credentials.json",
		nil,
		&info); err != nil {
		http.Error(w, "Error getting timeline, "+err.Error(), 500)
		return
	}
	if user, ok := info["screen_name"].(string); ok {
		//fmt.Printf("  username: %s\n", user)
		cookie := getSecureCookie(r)
		cookie.User = user
		setSecureCookie(w, cookie)
	}
	http.Redirect(w, r, redirect, 302)
}
開發者ID:amaudy,項目名稱:apptranslator,代碼行數:42,代碼來源:handler_login.go

示例3: ServeHTTP

func (h *authHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	var cred oauth.Credentials
	if err := getCookie(r, "auth", &cred); err != nil {
		if err != http.ErrNoCookie {
			http.Error(w, "Error reading auth cookie, "+err.Error(), 500)
			return
		}
		cred.Token = ""
	}

	var pcred *oauth.Credentials
	if cred.Token != "" && cred.Secret != "" {
		pcred = &cred
	}

	if pcred == nil && !h.optional {
		http.Error(w, "Not logged in.", 403)
		return
	}

	h.handler(w, r, pcred)
}
開發者ID:sadasant,項目名稱:go-oauth,代碼行數:22,代碼來源:main.go


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