如何在 OAUTH 2.0 中设置 expire_in? [英] How to set expire_in in OAUTH 2.0?

查看:85
本文介绍了如何在 OAUTH 2.0 中设置 expire_in?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 OAuth 2.0 和 spring 来生成令牌,我想手动设置 expire_in 以便令牌可以根据我的标准过期.有人帮帮我吗?

这是我的回答:

<预><代码>{access_token:c7a6cb95-1506-40e7-87d1-ddef0a239f64"token_type:承载者"expires_in: 43199范围:阅读"}

解决方案

public interface OAuth2AccessToken {public static String BEARER_TYPE = "Bearer";public static String OAUTH2_TYPE = "OAuth2";/*** 授权服务器发布的访问令牌.该值是必需的.*/public static String ACCESS_TOKEN = "access_token";/*** 如 <a 中描述的那样发行的令牌类型* href="http://tools.ietf.org/html/draft-ietf-oauth-v2-22#section-7.1">第 7.1 节</a>.值不区分大小写.* 该值是必需的.*/public static String TOKEN_TYPE = "token_type";/*** 访问令牌的生命周期(以秒为单位).例如,值3600"表示访问令牌将* 响应生成后一小时后过期.该值是可选的.*/public static String EXPIRES_IN = "expires_in";/***刷新令牌可用于使用与所述相同的授权授予获取新的访问令牌* 在<a href="http://tools.ietf.org/html/draft-ietf-oauth-v2-22#section-6">第6节</a>.该值是可选的.*/public static String REFRESH_TOKEN = "refresh_token";/*** 访问令牌的范围,如 <a 所述* href="http://tools.ietf.org/html/draft-ietf-oauth-v2-22#section-3.3">第 3.3 节</a>*/公共静态字符串范围=范围";/*** 令牌序列化程序使用 additionalInformation 映射来导出 OAuth 扩展使用的任何字段.* @return 从序列化令牌中的字段名称到要导出的值的映射.默认序列化器* 利用 Jackson 的 Java 对象自动 JSON 映射(用于令牌端点流)或隐式调用* .toString() 在值"对象(对于隐式流)上作为序列化过程的一部分.*/映射<字符串,对象>获取附加信息();设置<字符串>获取范围();OAuth2RefreshToken getRefreshToken();String getTokenType();布尔值 isExpired();日期 getExpiration();int getExpiresIn();字符串 getValue();}

I am using OAuth 2.0 with spring for token generation and I want to set expire_in manually so token can expire as per my criteria. Any one help me?

This is my response:

{
    access_token: "c7a6cb95-1506-40e7-87d1-ddef0a239f64"
    token_type: "bearer"
    expires_in: 43199
    scope: "read"
}

解决方案

public interface OAuth2AccessToken {

    public static String BEARER_TYPE = "Bearer";

    public static String OAUTH2_TYPE = "OAuth2";

    /**
     * The access token issued by the authorization server. This value is REQUIRED.
     */
    public static String ACCESS_TOKEN = "access_token";

    /**
     * The type of the token issued as described in <a
     * href="http://tools.ietf.org/html/draft-ietf-oauth-v2-22#section-7.1">Section 7.1</a>. Value is case insensitive.
     * This value is REQUIRED.
     */
    public static String TOKEN_TYPE = "token_type";

    /**
     * The lifetime in seconds of the access token. For example, the value "3600" denotes that the access token will
     * expire in one hour from the time the response was generated. This value is OPTIONAL.
     */
    public static String EXPIRES_IN = "expires_in";

    /**
     * The refresh token which can be used to obtain new access tokens using the same authorization grant as described
     * in <a href="http://tools.ietf.org/html/draft-ietf-oauth-v2-22#section-6">Section 6</a>. This value is OPTIONAL.
     */
    public static String REFRESH_TOKEN = "refresh_token";

    /**
     * The scope of the access token as described by <a
     * href="http://tools.ietf.org/html/draft-ietf-oauth-v2-22#section-3.3">Section 3.3</a>
     */
    public static String SCOPE = "scope";

    /**
     * The additionalInformation map is used by the token serializers to export any fields used by extensions of OAuth.
     * @return a map from the field name in the serialized token to the value to be exported. The default serializers 
     * make use of Jackson's automatic JSON mapping for Java objects (for the Token Endpoint flows) or implicitly call 
     * .toString() on the "value" object (for the implicit flow) as part of the serialization process.
     */
    Map<String, Object> getAdditionalInformation();

    Set<String> getScope();

    OAuth2RefreshToken getRefreshToken();

    String getTokenType();

    boolean isExpired();

    Date getExpiration();

    int getExpiresIn();

    String getValue();

}

这篇关于如何在 OAUTH 2.0 中设置 expire_in?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆