OAuth2 + Kubernetes + Ingress

时间:2018-09-03 14:29:06

标签: nginx oauth-2.0 kubernetes kubernetes-ingress

我的OAuth2微服务具有在kubernetes上部署的授权码方法。 我在Ingress nginx网关上注册了微服务路径。 喜欢:

"annotations": {
  "ingress.kubernetes.io/secure-backends": "true",
  "ingress.kubernetes.io/ssl-redirect": "false",
  "kubernetes.io/ingress.class": "nginx",
  "nginx.ingress.kubernetes.io/add-base-url": "true",
  "nginx.ingress.kubernetes.io/rewrite-target": "/"
}

    ......


        {
          "path": "/oauth",
          "backend": {
            "serviceName": "oauth2service-service",
            "servicePort": 8090
          }
        },

在Oauth2微服务中,我有以下配置:

@Override
protected void configure(HttpSecurity http) throws Exception {
 http.requestMatchers()
.antMatchers(HttpMethod.GET, "/oauth/login", "/oauth/authorize", "/oauth/token", "/oauth/logout", "/oauth/oauth/login")
.antMatchers(HttpMethod.POST, "/oauth/login", "/oauth/oauth/login")
 .and()
 .authorizeRequests()
 .anyRequest().authenticated()
 .and()
 .formLogin().loginPage("/oauth/login").permitAll()
 .and().logout().deleteCookies("auth_code", "JSESSIONID").invalidateHttpSession(true).logoutSuccessUrl(logoutURL)
 .and().csrf().disable();
 http.authorizeRequests().antMatchers("/oauth/check_token").permitAll();

}

如果我将入口配置为:

        {
          "path": "/",
          "backend": {
            "serviceName": "oauth2service-service",
            "servicePort": 8090
          }
        },

它与“ path”:“ /”一起使用,但是我需要/ ouath。

我需要下一个Flow才能正确运行我的OAuth2应用程序:

/ oauth / oauth / authorize?client_id =&response_type = code&scope = read&redirect_uri = https://www.getpostman.com/oauth2/callback

/ oauth / login->错误:OAuth服务器错误

enter image description here

正确的流量应该是:

/ oauth / oauth / authorize?client_id =&response_type = code&scope = read&redirect_uri = https://www.getpostman.com/oauth2/callback->获取302 http代码

/ oauth / login->获取307 http代码

/ oauth / oauth / login-> POST 302 HTTP代码

/ oauth / authorize?client_id =&response_type = code&scope = read&redirect_uri = https://www.getpostman.com/oauth2/callback->获取307 http代码

/ oauth / oauth / authorize?client_id =&response_type = code&scope = read&redirect_uri = https://www.getpostman.com/oauth2/callback->获取302 http代码

/ oauth2 / callback?code = S9z8Jn->获取301 http代码

但是我不知道如何配置OAuth2和入口以进行重定向。

谢谢您的时间。

0 个答案:

没有答案