@Documented @MethodLifeCycle(value=OAuth2LifeCycle.class) @RequestAttributes @Retention(value=RUNTIME) @Target(value={TYPE,METHOD}) public @interface OAuth2
Modifier and Type | Required Element and Description |
---|---|
String |
clientId
客户端ID
|
String |
clientSecret
客户端秘钥
|
String |
tokenUri
请求Token的URL地址,通过请求该地址以获得Token
|
Modifier and Type | Optional Element and Description |
---|---|
String[] |
body
其他的请求体参数。例如:
|
String |
cacheId
缓存ID,为了确保缓存唯一(防止被其他同类型请求的缓存Token覆盖)建议设置此值。
虽然系统已经预设了一部分缓存key内容,但是也无法保证缓存不被其他配置覆盖,因此可能需要您手动设置该值。
默认使用:tokenUri/clientId/grantType/scope/username 组成一个KEY。
假如设置了 cacheId 将会直接把 cacheId 作为缓冲 KEY。
该参数在我引入了适配微信公众号开发请求 access_token 时发现可能需要这样设置,因为微信公众号传入的是 appid 而不是 clientId,
因此可能会有人把 clientId 设置为空字符串,此时假如系统中管理了两个公众号的接口请求,就可能引起缓存 Token 错乱、被覆盖的可能性。
|
OAuth2.GrantType |
grantType
grantType 类型
|
String |
grantTypeValue
强制设置 grantType 值,该值将会覆盖 grantType 的设置。
由于一些特殊的情况,grantType 的值跟 GrantType 中预设的不一致,可以通过设置该参数来强制覆盖 GrantType 的参数值。
例如微信公众号开发的 grant_type = client_credential ,而预设中的是 CLIENT_CREDENTIALS("client_credentials") 两者不一致导致的请求失败
|
String |
password
密码
|
String[] |
query
其他的Query参数。例如:
|
int |
refreshAtExpiresBefore
刷新前剩余秒数,即在 expires_in 剩余多少秒进行刷新。默认:600秒5分钟。
不会主动触发刷新,只有在Token有效期最后5分钟内有请求的时候才会触发刷新。
假如刷新失败将一直使用旧的Token,直到最后旧的Token失效时才会重新获取Token
|
String |
scope
范围
|
OAuth2.TokenAt |
tokenAt
Token 信息位置。默认通过Header传输
|
String |
tokenPrefix
Token 前缀,会强制覆盖 tokenAt 的设置。例如:
|
String |
tokenVariable
传输 Token 的参数名,会强制覆盖 tokenAt 的设置。例如:
|
String |
username
用户名
|
public abstract String cacheId
@Nonnull public abstract OAuth2.GrantType grantType
public abstract String grantTypeValue
public abstract String scope
public abstract int refreshAtExpiresBefore
public abstract String username
public abstract String password
public abstract String[] query
{ "名称1:值1", "名称2:值2", "other-info:其他参数值" }
public abstract String[] body
{ "名称1:值1", "名称2:值2", "other-info:其他参数值" }
@Nonnull public abstract OAuth2.TokenAt tokenAt
public abstract String tokenVariable
Token在Header的时候默认为 Authorization
Token在Body的时候默认为 access_token
public abstract String tokenPrefix
Token在Header的时候默认为 Bearer 前缀
Token在Body的时候需默认该项设置为空字符串
Copyright © 2020. All rights reserved.