-
Notifications
You must be signed in to change notification settings - Fork 6.1k
OAuth2AuthorizationRequest support for some non-standard oauth provider #7714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@okhowang You can customize the You can also customize the Token Request. I'm going to close this issue as I feel I answered your question. |
OAuth2AuthorizationRequestResolver has many common logic, for example pkcs and so on. |
@okhowang I'm not sure I understand your request. Can you provide a more detailed explanation or even a code sample of what you would like to accomplish? |
for example, when call with a standard oauth provider of course, i can customize OAuth2AuthorizationRequestResolver to do this. |
Ok I understand now. So let's say we add However, it still will not let you change the parameter names. You need to change |
final redirect uri is make by private fun set(map: MultiValueMap<String, String>, name: String, value: String) {
map[parameterNameMap[name] ?: name] = value
}
private fun buildAuthorizationRequestUri(): String {
val parameters = LinkedMultiValueMap<String, String>()
set(parameters, OAuth2ParameterNames.RESPONSE_TYPE, this.responseType.value)
set(parameters, OAuth2ParameterNames.CLIENT_ID, this.clientId)
scopes?.let { set(parameters, OAuth2ParameterNames.SCOPE, it.joinToString(" ")) }
state?.let { set(parameters, OAuth2ParameterNames.STATE, it) }
redirectUri?.let { set(parameters, OAuth2ParameterNames.REDIRECT_URI, it) }
additionalParameters?.let { it.forEach { (key, value) -> parameters.set(key, value.toString()) } }
return UriComponentsBuilder.fromHttpUrl(this.authorizationUri)
.queryParams(parameters)
.fragment(clientRegistration.authorizationHash()) // add custom fragment
.encode(StandardCharsets.UTF_8)
.build()
.toUriString()
} |
In parameters, it looks like ok |
You can update like this: this.resolver.setAuthorizationRequestCustomizer(customizer -> {
// TODO Append #wechat_redirect (Option 1)
customizer.redirectUri(...);
// TODO Append #wechat_redirect (Option 2)
customizer.parameters(parameters -> {
String redirectUri = (String) parameters.get(OAuth2ParameterNames.REDIRECT_URI);
redirectUri += "#wechat_redirect";
parameters.put(OAuth2ParameterNames.REDIRECT_URI, redirectUri);
});
});
I'm not sure if an interface would be better. I believe a Do you see any limitations with the |
this.resolver.setAuthorizationRequestCustomizer(customizer -> {
customizer.hash("wechat_redirect");
}); |
I thought you need to add to
|
I'm sorry for bad case |
ok so |
LGTM |
请问你是如何在authorizationRequestCustomizer中区分标准oauth2 provider与非标准的oauth2 provider? |
这个是在 |
@jgrandja i have done it,but something not good here, import org.springframework.security.oauth2.client.web.DefaultOAuth2AuthorizationRequestResolver;
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest;
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
import org.springframework.util.Assert;
import org.springframework.web.util.UriBuilder;
import java.net.URI;
import java.util.Map;
import java.util.function.Consumer;
/**
* customizer {@link OAuth2AuthorizationRequest}
* <p>
* client_id to appid ,add fragment wechat_redirect
* @see DefaultOAuth2AuthorizationRequestResolver#setAuthorizationRequestCustomizer(Consumer)
* @author felord.cn
*/
public class WechatOAuth2AuthorizationRequestCustomizer {
private static final String WECHAT_APP_ID = "appid";
private static final String WECHAT_FRAGMENT = "wechat_redirect";
private final String wechatRegistrationId;
public WechatOAuth2AuthorizationRequestCustomizer(String wechatRegistrationId) {
Assert.notNull(wechatRegistrationId, "wechat registrationId flag must not be null");
this.wechatRegistrationId = wechatRegistrationId;
}
public void customize(OAuth2AuthorizationRequest.Builder builder) {
//todo i need a method to get registrationId here So that the following code logic can be executed
builder.parameters(WechatOAuth2AuthorizationRequestCustomizer::wechatParametersConsumer);
builder.authorizationRequestUri(WechatOAuth2AuthorizationRequestCustomizer::authorizationRequestUriFunction);
}
private static void wechatParametersConsumer(Map<String, Object> parameters) {
// client_id replace into appid here
LinkedHashMap<String, Object> linkedParameters = new LinkedHashMap<>();
// k v must be ordered
parameters.forEach((k,v)->{
if (OAuth2ParameterNames.CLIENT_ID.equals(k)){
linkedParameters.put(WECHAT_APP_ID,v);
}else {
linkedParameters.put(k,v);
}
});
parameters.clear();
parameters.putAll(linkedParameters);
}
private static URI authorizationRequestUriFunction(UriBuilder builder) {
// add wechat fragment here
return builder.fragment(WECHAT_FRAGMENT).build();
}
} |
Summary
in china, some oauth provider's implementation is not standard enough
for example wechat, it use
appid
instead ofclient_id
and must add url hash#wechat_redirect
can we add more customization for OAuth2AuthorizationRequest and OAuth2AuthorizationRequestResolver
Actual Behavior
Expected Behavior
Configuration
Version
Sample
The text was updated successfully, but these errors were encountered: