本文整理匯總了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))
}
}
示例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
}
示例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))
}
}