Получение токена доступа или токена jwt с помощью springboot webflux - PullRequest
0 голосов
/ 06 ноября 2019

У меня есть следующая информация: Тип гранта: URL-адрес токена доступа для учетных данных клиента: https://host/adfs/oauth2/token идентификатор клиента: clientId секрет клиента: clientSecret

Моя задача - создать сервер ресурсов, который получит jwtили токен доступа в шапке. Как только токен будет проверен, я верну запрашиваемый ресурс.

Проблема: я не уверен, как проверить токен с помощью пружинного реактива.

Примечание. Сервер включен с открытым идентификатором.

Я пробовал: https://docs.spring.io/spring-security/site/docs/5.1.0.BUILD-SNAPSHOT/reference/html/webclient.html

и https://www.youtube.com/watch?v=1N-xwmoN83w&t=1338s

, если вы нажмете

https://host/adfs/.well-known/openid-configuration

{ 
   "issuer":"https:\/\/host\/adfs",
   "authorization_endpoint":"https:\/\/host\/adfs\/oauth2\/authorize\/",
   "token_endpoint":"https:\/\/host\/adfs\/oauth2\/token\/",
   "jwks_uri":"https:\/\/host\/adfs\/discovery\/keys",
   "token_endpoint_auth_methods_supported":[ 
      "client_secret_post",
      "client_secret_basic",
      "private_key_jwt",
      "windows_client_authentication"
   ],
   "response_types_supported":[ 
      "code",
      "id_token",
      "code id_token",
      "id_token token",
      "code token",
      "code id_token token"
   ],
   "response_modes_supported":[ 
      "query",
      "fragment",
      "form_post"
   ],
   "grant_types_supported":[ 
      "authorization_code",
      "refresh_token",
      "client_credentials",
      "urn:ietf:params:oauth:grant-type:jwt-bearer",
      "implicit",
      "password",
      "srv_challenge",
      "urn:ietf:params:oauth:grant-type:device_code",
      "device_code"
   ],
   "subject_types_supported":[ 
      "pairwise"
   ],
   "scopes_supported":[ 
      "email",
      "profile",
      "winhello_cert",
      "logon_cert",
      "user_impersonation",
      "aza",
      "vpn_cert",
      "openid",
      "allatclaims"
   ],
   "id_token_signing_alg_values_supported":[ 
      "RS256"
   ],
   "token_endpoint_auth_signing_alg_values_supported":[ 
      "RS256"
   ],
   "access_token_issuer":"http:\/\/host\/adfs\/services\/trust",
   "claims_supported":[ 
      "aud",
      "iss",
      "iat",
      "exp",
      "auth_time",
      "nonce",
      "at_hash",
      "c_hash",
      "sub",
      "upn",
      "unique_name",
      "pwd_url",
      "pwd_exp",
      "mfa_auth_time",
      "sid"
   ],
   "microsoft_multi_refresh_token":true,
   "userinfo_endpoint":"https:\/\/host\/adfs\/userinfo",
   "capabilities":[ 

   ],
   "end_session_endpoint":"https:\/\/host\/adfs\/oauth2\/logout",
   "as_access_token_token_binding_supported":true,
   "as_refresh_token_token_binding_supported":true,
   "resource_access_token_token_binding_supported":true,
   "op_id_token_token_binding_supported":true,
   "rp_id_token_token_binding_supported":true,
   "frontchannel_logout_supported":true,
   "frontchannel_logout_session_supported":true,
   "device_authorization_endpoint":"https:\/\/host\/adfs\/oauth2\/devicecode"
}

У меня есть простой контроллер:

@RestController
public class Controller {
    @GetMapping("/hello")
    public String sayHello(){
        return "hello";
    }
}

и следующий класс:


@ConditionalOnClass({ EnableWebFluxSecurity.class, WebFilterChainProxy.class })
@ConditionalOnMissingBean(WebFilterChainProxy.class)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
@EnableWebFluxSecurity
public class WebSecurityConfig {


    @Bean
    SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {        http.authorizeExchange().anyExchange().authenticated().and().oauth2ResourceServer().jwt();
        return http.build();
    }

}

в свойствах приложения у меня есть: spring.security.oauth2.resourceserver.jwt.issuer-uri: valid-uri

Вот журнал: 2019-11-05 16: 00: 55.638 DEBUG 51492 --- [ctor-http-nio-3] oswsadapter.HttpWebHandlerAdapter: [7598cb39] HTTP GET "/привет "2019-11-05 16: 00: 55.746 DEBUG 51492 --- [ctor-http-nio-3] oswrfclient.ExchangeFunctions: [628b27eb] HTTP GET https://host/adfs/discovery/keys 2019-11-05 16:00:55.823 DEBUG 51492 --- [ctor-http-nio-4] oswrfclient.ExchangeFunctions: [628b27eb] Ответ 200 OK 2019-11-05 16: 00: 55.840 DEBUG 51492 --- [ctor-http-nio-4] oscore.codec.StringDecoder: [628b27eb] Декодированный "{" keys ": [{" kty ":" algo "," use ":" sig "," alg ":" HS234 "," kid ":" feafafa ","x5t ":" fKeeYG0K (усечено) ... 2019-11-05 16: 00: 55.858 ОТЛАДКА 51492 --- [ctor-http-nio-4] oswsadapter.HttpWebHandlerAdapter: [7598cb39] Завершено 401 НЕСАНКЦИОНИРОВАННО

...