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


Golang Client.ExchangeAuthCode方法代碼示例

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


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

示例1: handleCallbackFunc

func handleCallbackFunc(c *oidc.Client) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		code := r.URL.Query().Get("code")
		if code == "" {
			phttp.WriteError(w, http.StatusBadRequest, "code query param must be set")
			return
		}

		tok, err := c.ExchangeAuthCode(code)
		if err != nil {
			phttp.WriteError(w, http.StatusBadRequest, fmt.Sprintf("unable to verify auth code with issuer: %v", err))
			return
		}

		claims, err := tok.Claims()
		if err != nil {
			phttp.WriteError(w, http.StatusBadRequest, fmt.Sprintf("unable to construct claims: %v", err))
			return
		}

		s := fmt.Sprintf(`<html><body><p>Token: %v</p><p>Claims: %v </p>
        <a href="/resend?jwt=%s">Resend Verification Email</a>
</body></html>`, tok.Encode(), claims, tok.Encode())
		w.Write([]byte(s))
	}
}
開發者ID:adrianlop,項目名稱:dex,代碼行數:26,代碼來源:main.go

示例2: oidcCallback

func oidcCallback(c *oidc.Client, listenAddr string) (string, chan jose.JWT, error) {
	tokenChan := make(chan jose.JWT)
	l, err := net.Listen("tcp", listenAddr)
	if err != nil {
		return "", nil, err
	}
	oac, err := c.OAuthClient()
	if err != nil {
		return "", nil, err
	}
	f := func(w http.ResponseWriter, r *http.Request) {
		code := r.URL.Query().Get("code")
		if code == "" {
			return
		}
		token, err := c.ExchangeAuthCode(code)
		if err != nil {
			fmt.Fprintf(w, "error: %s", err)
			return
		}
		tokenChan <- token
		close(tokenChan)
		fmt.Fprintf(w, "Success! You can now close this window and go back to the CLI")
		l.Close()
	}
	go http.Serve(l, http.HandlerFunc(f))
	return oac.AuthCodeURL("", "", ""), tokenChan, err
}
開發者ID:polvi,項目名稱:oidccli,代碼行數:28,代碼來源:oidccli.go

示例3: handleCallbackFunc

func handleCallbackFunc(c *oidc.Client) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		code := r.URL.Query().Get("code")
		if code == "" {
			writeError(w, http.StatusBadRequest, "code query param must be set")
			return
		}

		tok, err := c.ExchangeAuthCode(code)
		if err != nil {
			writeError(w, http.StatusBadRequest, fmt.Sprintf("unable to verify auth code with issuer: %v", err))
			return
		}

		claims, err := tok.Claims()
		if err != nil {
			writeError(w, http.StatusBadRequest, fmt.Sprintf("unable to construct claims: %v", err))
			return
		}

		s := fmt.Sprintf("claims: %v", claims)
		w.Write([]byte(s))
	}
}
開發者ID:otsimo,項目名稱:watch,代碼行數:24,代碼來源:main.go


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