【问题标题】:Spring REST API modifying "oauth/token" org.springframework.security.oauth2.provider.endpoint TokenEndpoint to return additional InfoSpring REST API 修改“oauth/token” org.springframework.security.oauth2.provider.endpoint TokenEndpoint 以返回附加信息
【发布时间】:2017-04-24 07:26:26
【问题描述】:

您好,我正在寻求有关 Spring Security 的帮助,我有一个 Spring REST API 服务于 IOS 和 Android 堆栈,我们有一个用于登录应用程序的 oauth/token 端点,在确认后它会发回令牌。它是一个开箱即用的弹簧安全类 org.springframework.security.oauth2.provider.endpoint。我试图在响应中发送来自与用户相关的 api 的附加信息,以在登录时合并来自移动设备的 api 调用。我不知道该怎么做,或者最好的方法是什么......我应该创建一个新的 TokenEndpoint 类吗?这就是我为 spring-security 配置的一些 XML 的方式。

 <!-- OAUTH CONFIGS -->
<bean id="oauthAuthenticationEntryPoint" class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint">
    <property name="realmName" value="hcnavigator" />
</bean>

<bean id="clientCredentialsTokenEndpointFilter" class="org.springframework.security.oauth2.provider.client.ClientCredentialsTokenEndpointFilter">
    <property name="authenticationManager" ref="clientAuthenticationManager" />
</bean>

<bean id="accessDecisionManager" class="org.springframework.security.access.vote.UnanimousBased">
    <constructor-arg>
        <list>
            <bean class="org.springframework.security.oauth2.provider.vote.ScopeVoter" />
            <bean class="org.springframework.security.access.vote.RoleVoter" />
            <bean class="org.springframework.security.access.vote.AuthenticatedVoter" />
        </list>
    </constructor-arg>
</bean>

【问题讨论】:

    标签: java spring spring-security oauth


    【解决方案1】:

    TokenEnhancer (http://docs.spring.io/spring-security/oauth/apidocs/org/springframework/security/oauth2/provider/token/TokenEnhancer.html) 是您所需要的。您可以将其注入您的令牌服务 (http://docs.spring.io/spring-security/oauth/apidocs/org/springframework/security/oauth2/provider/token/DefaultTokenServices.html)。 TokenEnhancer 将在生成令牌后被调用,您可以在其enhance(...) 方法中向令牌响应中添加其他信息。

    【讨论】:

    • 很高兴听到这个消息:)
    猜你喜欢
    • 2018-04-26
    • 1970-01-01
    • 2015-04-26
    • 2015-05-28
    • 2013-09-11
    • 2013-01-06
    • 2019-05-31
    • 2016-09-06
    • 2015-11-10
    相关资源
    最近更新 更多