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