Spring Boot Oauth2 use multiple grant_types for for same URL

青春壹個敷衍的年華 提交于 2020-05-12 07:49:08

问题


Is it possible to configure Spring Boot to allow Oauth2 grant types password and authorization_code on the same URL. For example /boot

I have done basic authorization configuration as below

security:
  oauth2:
    client:
      accessTokenUri: http://UAA/oauth/token
      userAuthorizationUri: http://UAA/oauth/authorize
      clientId: ******
      clientSecret: ******
    resource:
      userInfoUri: http://UAA/userinfo

However all endpoints protected by this configuration use form login and redirect to UAA authorization URL even when request is sent with Authorization Bearer **** token header. That means even when I send a Authorization token in postman I get HTTP Status 302 along with HTML response for UAA login page.


回答1:


Instead of having configs in config file, you can configure authorization server to create OAuth clients. Then you can configure clients with multiple grant types, authorities, scopes etc...

   @Override
        public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
            clients.inMemory().withClient("client_id").authorizedGrantTypes("password", "client_credentials")
                    .secret("secret").authorities("Authority1", "Authority2").scopes("READ", "WRITE").resourceIds("resource_server_id");
    }

Please check This Spring OAuth sample for more details.



来源:https://stackoverflow.com/questions/50404610/spring-boot-oauth2-use-multiple-grant-types-for-for-same-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!