Exemplo n.º 1
0
// NewManager 创建Manager的实例
func NewManager() *Manager {
	m := &Manager{
		injector: inject.New(),
		rtcfg:    make(map[oauth2.ResponseType]*Config),
		gtcfg:    make(map[oauth2.GrantType]*Config),
	}
	// 设定参数默认值
	// 设定授权码的有效期为10分钟
	m.SetRTConfig(oauth2.Code, &Config{TokenExp: time.Minute * 10})
	// 设定简化模式授权令牌的有效期为1小时
	m.SetRTConfig(oauth2.Token, &Config{TokenExp: time.Hour * 1})

	// 设定授权码模式令牌的有效期为2小时,更新令牌的有效期为3天
	m.SetGTConfig(oauth2.AuthorizationCodeCredentials, &Config{TokenExp: time.Hour * 2, RefreshExp: time.Hour * 24 * 3})
	// 设定密码模式令牌的有效期为2小时,更新令牌的有效期为7天
	m.SetGTConfig(oauth2.PasswordCredentials, &Config{TokenExp: time.Hour * 2, RefreshExp: time.Hour * 24 * 7})
	// 设定客户端模式令牌的有效期为1小时
	m.SetGTConfig(oauth2.ClientCredentials, &Config{TokenExp: time.Hour * 2})

	return m
}
Exemplo n.º 2
0
// NewManager Create to authorization management instance
func NewManager() *Manager {
	return &Manager{
		injector: inject.New(),
		gtcfg:    make(map[oauth2.GrantType]*Config),
	}
}