本文整理汇总了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))
}
}