本文整理匯總了Golang中github.com/backerman/eveindy/pkg/db.LocalDB.AuthenticateSession方法的典型用法代碼示例。如果您正苦於以下問題:Golang LocalDB.AuthenticateSession方法的具體用法?Golang LocalDB.AuthenticateSession怎麽用?Golang LocalDB.AuthenticateSession使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/backerman/eveindy/pkg/db.LocalDB
的用法示例。
在下文中一共展示了LocalDB.AuthenticateSession方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: CRESTCallbackListener
// CRESTCallbackListener returns a web handler function that listens for a CREST
// SSO callback and accepts the results of authentication.
func CRESTCallbackListener(localdb db.LocalDB, auth evesso.Authenticator, sess server.Sessionizer) web.HandlerFunc {
return func(c web.C, w http.ResponseWriter, r *http.Request) {
// Verify state value.
s := sess.GetSession(&c, w, r)
passedState := r.FormValue("state")
if passedState != s.State {
// CSRF attempt or session expired; reject.
http.Error(w, "Returned state not valid for this user.", http.StatusBadRequest)
log.Printf("Got state %#v, expected state %#v", passedState, s.State)
w.Write([]byte(`{"status": "Error"}`))
return
}
// Extract code from query parameters.
code := r.FormValue("code")
// Exchange it for a token.
tok, err := auth.Exchange(code)
if err != nil {
http.Error(w, `{"status": "Error"}`, http.StatusInternalServerError)
log.Printf("Error exchanging token: %v", err)
return
}
// Get character information.
charInfo, err := auth.CharacterInfo(tok)
if err != nil {
http.Error(w, `{"status": "Error"}`, http.StatusInternalServerError)
log.Printf("Error getting character information: %v; token was %+v", err, tok)
return
}
// Update session in database.
err = localdb.AuthenticateSession(s.Cookie, tok, charInfo)
if err != nil {
http.Error(w, `{"status": "Error"}`, http.StatusInternalServerError)
log.Printf("Unable to update session post-auth: %v; info was %+v", err, charInfo)
return
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusOK)
w.Write([]byte(`
<html>
<head>
<title>Authenticated</title>
</head>
<body>
<p>OK.</p>
<script type="text/javascript">
window.onload = function() {
window.opener.hasAuthenticated();
window.close();
}
</script>
</body>
</html>
`))
}
}