本文整理匯總了Golang中github.com/martini-contrib/oauth2.Tokens.Expired方法的典型用法代碼示例。如果您正苦於以下問題:Golang Tokens.Expired方法的具體用法?Golang Tokens.Expired怎麽用?Golang Tokens.Expired使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/martini-contrib/oauth2.Tokens
的用法示例。
在下文中一共展示了Tokens.Expired方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: DomainChecker
//DomainChecker - check the authenticated users domain to see if it is in the whitelist
func DomainChecker(res http.ResponseWriter, tokens oauth2.Tokens) {
userInfo := GetUserInfo(tokens)
if domain, ok := userInfo["domain"]; !ok || tokens.Expired() || isBlockedDomain(domain.(string)) {
res.WriteHeader(FailureStatus)
res.Write(AuthFailureResponse)
}
}
示例2: RequestData
/* Middleware to:
- Retrieve data from github if user is logged in and data is not stored in sessions
- Delete session data if user logged out */
func RequestData(tokens oauth2.Tokens, session sessions.Session) {
if !tokens.Expired() && session.Get("username") == nil {
access := tokens.Access()
req, _ := http.NewRequest("GET", "https://api.github.com/user?access_token="+access, nil)
client := &http.Client{}
resp, _ := client.Do(req)
body, _ := ioutil.ReadAll(resp.Body)
parse := map[string]interface{}{}
json.Unmarshal([]byte(string(body)), &parse)
session.Set("username", parse["login"])
session.Set("user_id", parse["id"])
session.Set("avatar", parse["avatar_url"])
log.Println("retrieved data")
} else if tokens.Expired() && session.Get("username") != nil {
session.Clear()
log.Println("removed data")
}
}