找不到登录Authserver Spring OAuth2的重定向



我在一个应用程序中有一个带有spring的osterizationserver,我想在我的API中使用Bearer令牌授权和对呼叫进行验证。

我认为交流很好(我认为),但是当令牌是有效的显示时:

{
  "timestamp": 1466606797251,
  "status": 404,
  "error": "Not Found",
  "message": "No message available",
  "path": "/api/authorizationServer/login"
}

当令牌无效时说:

{
  "error": "invalid_token",
  "error_description": "Access token expired: cc281c6a-aeef-401c-879a-624c94058c7b"
}

为什么找不到显示?

编辑:

我的休息服务非常简单:

应用程序:

@SpringBootApplication
@EnableOAuth2Sso
public class Application extends SpringBootServletInitializer {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

终点:

@Controller
public class HelloController {
    @RequestMapping(value = "/hello",
            method = RequestMethod.GET)
    @ResponseBody
    public String sayHello() {
        return "Hello User!";
    }
}

配置:

security:
  oauth2:
    client:
      clientId: client
      clientSecret: secret
      accessTokenUri: http://localhost:8080/api/v1/secure/oauth/token
      userAuthorizationUri: http://localhost:8080/api/v1/secure/oauth/authorize
      clientAuthenticationScheme: header
    resource:
      tokenInfoUri: http://localhost:8080/api/v1/secure/oauth/check_token
server:
  port: 8082
  contextPath: /api/v1/auth

它对我有用:

    @Override
    public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
        oauthServer
                .checkTokenAccess("permitAll()");
    }

在authserver上:

    @Configuration
    @EnableWebSecurity
    @EnableGlobalMethodSecurity(jsr250Enabled = true)
    protected static class SecurityConfig extends WebSecurityConfigurerAdapter {
        @Order(2)
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http
                    .authorizeRequests().anyRequest().authenticated()
                    .and()
                    .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER)
            ;
        }
        @Order(1)
        @Override
        public void configure(WebSecurity web) throws Exception {
            web
                    .ignoring()
                    .antMatchers("/api/**");
        }
    }

在Resourceerver上

正如我的评论所说:

在传入的请求下,弹簧首先检查令牌有效性。
如果令牌无效,则会被invalid_token消息扔掉。
如果令牌有效,请将请求转发给控制器。但是就您而言,/login上没有映射的URL,因此您遇到了404。

甚至在检查URL是否存在之前检查令牌有效性是一种想要的行为,这就是为什么您在非现有URL上包含invalid_token的原因。

最新更新