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