zoukankan      html  css  js  c++  java
  • Spring Security 5.x Invalid Authorization Grant Type (password) for Client Registration with Id: reader

    客户端授权模式配置

    authorizationGrantType: password
    

    默认的授权请求解析不支持password模式,只支持AUTHORIZATION_CODE和IMPLICIT;
    源码如下
    DefaultOAuth2AuthorizationRequestResolver

    private OAuth2AuthorizationRequest resolve(HttpServletRequest request, String registrationId, String redirectUriAction) {
            if (registrationId == null) {
                return null;
            } else {
                ClientRegistration clientRegistration = this.clientRegistrationRepository.findByRegistrationId(registrationId);
                if (clientRegistration == null) {
                    throw new IllegalArgumentException("Invalid Client Registration with Id: " + registrationId);
                } else {
                    Map<String, Object> attributes = new HashMap();
                    attributes.put("registration_id", clientRegistration.getRegistrationId());
                    Builder builder;
                    if (AuthorizationGrantType.AUTHORIZATION_CODE.equals(clientRegistration.getAuthorizationGrantType())) {
                        builder = OAuth2AuthorizationRequest.authorizationCode();
                        Map<String, Object> additionalParameters = new HashMap();
                        if (!CollectionUtils.isEmpty(clientRegistration.getScopes()) && clientRegistration.getScopes().contains("openid")) {
                            this.addNonceParameters(attributes, additionalParameters);
                        }
    
                        if (ClientAuthenticationMethod.NONE.equals(clientRegistration.getClientAuthenticationMethod())) {
                            this.addPkceParameters(attributes, additionalParameters);
                        }
    
                        builder.additionalParameters(additionalParameters);
                    } else {
                        if (!AuthorizationGrantType.IMPLICIT.equals(clientRegistration.getAuthorizationGrantType())) {
                            throw new IllegalArgumentException("Invalid Authorization Grant Type (" + clientRegistration.getAuthorizationGrantType().getValue() + ") for Client Registration with Id: " + clientRegistration.getRegistrationId());
                        }
    
                        builder = OAuth2AuthorizationRequest.implicit();
                    }
    
                    String redirectUriStr = expandRedirectUri(request, clientRegistration, redirectUriAction);
                    OAuth2AuthorizationRequest authorizationRequest = builder.clientId(clientRegistration.getClientId()).authorizationUri(clientRegistration.getProviderDetails().getAuthorizationUri()).redirectUri(redirectUriStr).scopes(clientRegistration.getScopes()).state(this.stateGenerator.generateKey()).attributes(attributes).build();
                    return authorizationRequest;
                }
            }
        }
    
    
  • 相关阅读:
    vue , debounce 使用
    git 合并代码
    vue-snippet-模板
    旋转字符串
    给一个整数数组,找到两个数使得他们的和等于一个给定的数 target。
    水仙花数[js]
    一道笔试题(vue,react)
    OC中一些基本概念
    如何添加渐变?
    UIBarButtonItem关于全局修改,局部修改
  • 原文地址:https://www.cnblogs.com/jinit/p/14197121.html
Copyright © 2011-2022 走看看