KEYCLOAK-364 Show access denied if social login is cancelled
This commit is contained in:
1 parent
6dc156712e
commit
0214827492
12 files changed
+80
-48
No files matched your search
@@ -51,6 +51,15 @@ public abstract class AbstractOAuth2Provider implements SocialProvider {
|
||||
|
||||
@Override
|
||||
public SocialUser processCallback(SocialProviderConfig config, AuthCallback callback) throws SocialProviderException {
|
||||
String error = callback.getQueryParam("error");
|
||||
if (error != null) {
|
||||
if (error.equals("access_denied")) {
|
||||
throw new SocialAccessDeniedException();
|
||||
} else {
|
||||
throw new SocialProviderException(error);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
String code = callback.getQueryParam(CODE);
|
||||
|
||||
@@ -82,9 +91,4 @@ public abstract class AbstractOAuth2Provider implements SocialProvider {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRequestIdParamName() {
|
||||
return STATE;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.keycloak.social;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
*/
|
||||
public class SocialAccessDeniedException extends SocialProviderException {
|
||||
}
|
||||
@@ -31,8 +31,6 @@ public interface SocialProvider {
|
||||
|
||||
AuthRequest getAuthUrl(SocialProviderConfig config) throws SocialProviderException;
|
||||
|
||||
String getRequestIdParamName();
|
||||
|
||||
String getName();
|
||||
|
||||
SocialUser processCallback(SocialProviderConfig config, AuthCallback callback) throws SocialProviderException;
|
||||
|
||||
@@ -28,6 +28,9 @@ public class SocialProviderException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected SocialProviderException() {
|
||||
}
|
||||
|
||||
public SocialProviderException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ package org.keycloak.social.twitter;
|
||||
|
||||
import org.keycloak.social.AuthCallback;
|
||||
import org.keycloak.social.AuthRequest;
|
||||
import org.keycloak.social.SocialAccessDeniedException;
|
||||
import org.keycloak.social.SocialProvider;
|
||||
import org.keycloak.social.SocialProviderConfig;
|
||||
import org.keycloak.social.SocialProviderException;
|
||||
@@ -67,6 +68,10 @@ public class TwitterProvider implements SocialProvider {
|
||||
|
||||
@Override
|
||||
public SocialUser processCallback(SocialProviderConfig config, AuthCallback callback) throws SocialProviderException {
|
||||
if (callback.getQueryParam("denied") != null) {
|
||||
throw new SocialAccessDeniedException();
|
||||
}
|
||||
|
||||
try {
|
||||
Twitter twitter = new TwitterFactory().getInstance();
|
||||
twitter.setOAuthConsumer(config.getKey(), config.getSecret());
|
||||
@@ -86,9 +91,4 @@ public class TwitterProvider implements SocialProvider {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRequestIdParamName() {
|
||||
return "oauth_token";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user