本文整理匯總了Golang中github.com/lonelycode/osin.AccessData.ExpiresIn方法的典型用法代碼示例。如果您正苦於以下問題:Golang AccessData.ExpiresIn方法的具體用法?Golang AccessData.ExpiresIn怎麽用?Golang AccessData.ExpiresIn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/lonelycode/osin.AccessData
的用法示例。
在下文中一共展示了AccessData.ExpiresIn方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SaveAccess
// SaveAccess will save a token and it's access data to redis
func (r RedisOsinStorageInterface) SaveAccess(accessData *osin.AccessData) error {
authDataJSON, marshalErr := json.Marshal(accessData)
if marshalErr != nil {
return marshalErr
}
key := ACCESS_PREFIX + accessData.AccessToken
log.Debug("Saving ACCESS key: ", key)
// Overide default ExpiresIn:
if config.OauthTokenExpire != 0 {
accessData.ExpiresIn = config.OauthTokenExpire
}
r.store.SetKey(key, string(authDataJSON), int64(accessData.ExpiresIn))
// Create a SessionState object and register it with the authmanager
var newSession SessionState
unmarshalErr := json.Unmarshal([]byte(accessData.UserData.(string)), &newSession)
if unmarshalErr != nil {
log.Error("Couldn't decode SessionState from UserData")
log.Error(unmarshalErr)
return unmarshalErr
}
// Set the client ID for analytics
newSession.OauthClientID = accessData.Client.GetId()
// Override timeouts so that we can be in sync with Osin
newSession.Expires = time.Now().Unix() + int64(accessData.ExpiresIn)
// Use the default session expiry here as this is OAuth
r.sessionManager.UpdateSession(accessData.AccessToken, newSession, newSession.Expires)
// Store the refresh token too
if accessData.RefreshToken != "" {
if accessDataJSON, marshalErr := json.Marshal(accessData); marshalErr != nil {
return marshalErr
} else {
key := REFRESH_PREFIX + accessData.RefreshToken
log.Debug("Saving REFRESH key: ", key)
refreshExpire := int64(1209600) // 14 days
if config.OauthRefreshExpire != 0 {
refreshExpire = config.OauthRefreshExpire
}
r.store.SetKey(key, string(accessDataJSON), refreshExpire)
log.Debug("STORING ACCESS DATA: ", string(accessDataJSON))
return nil
}
}
return nil
}
示例2: SaveAccess
// SaveAccess will save a token and it's access data to redis
func (r RedisOsinStorageInterface) SaveAccess(accessData *osin.AccessData) error {
authDataJSON, marshalErr := json.Marshal(accessData)
if marshalErr != nil {
return marshalErr
}
key := ACCESS_PREFIX + accessData.AccessToken
log.Debug("Saving ACCESS key: ", key)
// Overide default ExpiresIn:
if config.OauthTokenExpire != 0 {
accessData.ExpiresIn = config.OauthTokenExpire
}
r.store.SetKey(key, string(authDataJSON), int64(accessData.ExpiresIn))
// Create a SessionState object and register it with the authmanager
var newSession SessionState
// ------
checkPolicy := true
if accessData.UserData != nil {
checkPolicy = false
marshalErr := json.Unmarshal([]byte(accessData.UserData.(string)), &newSession)
if marshalErr != nil {
log.Info("Couldn't decode SessionState from UserData, checking policy: ", marshalErr)
checkPolicy = true
}
}
if checkPolicy {
// defined in JWT middleware
sessionFromPolicy, notFoundErr := generateSessionFromPolicy(accessData.Client.GetPolicyID(), "", false)
if notFoundErr != nil {
return errors.New("Couldn't use policy or key rules to create token, failing")
}
newSession = sessionFromPolicy
}
// ------
// Set the client ID for analytics
newSession.OauthClientID = accessData.Client.GetId()
// Override timeouts so that we can be in sync with Osin
newSession.Expires = time.Now().Unix() + int64(accessData.ExpiresIn)
// Use the default session expiry here as this is OAuth
r.sessionManager.UpdateSession(accessData.AccessToken, newSession, int64(accessData.ExpiresIn))
// Store the refresh token too
if accessData.RefreshToken != "" {
accessDataJSON, marshalErr := json.Marshal(accessData)
if marshalErr != nil {
return marshalErr
}
key := REFRESH_PREFIX + accessData.RefreshToken
log.Debug("Saving REFRESH key: ", key)
refreshExpire := int64(1209600) // 14 days
if config.OauthRefreshExpire != 0 {
refreshExpire = config.OauthRefreshExpire
}
r.store.SetKey(key, string(accessDataJSON), refreshExpire)
log.Debug("STORING ACCESS DATA: ", string(accessDataJSON))
return nil
}
return nil
}