use of org.keycloak.models.KeycloakUriInfo in project keycloak by keycloak.
the class DeviceGrantType method denyOAuth2DeviceAuthorization.
public static Response denyOAuth2DeviceAuthorization(AuthenticationSessionModel authSession, LoginProtocol.Error error, KeycloakSession session) {
KeycloakContext context = session.getContext();
RealmModel realm = context.getRealm();
KeycloakUriInfo uri = context.getUri();
UriBuilder uriBuilder = DeviceGrantType.oauth2DeviceVerificationCompletedUrl(uri);
String errorType = OAuthErrorException.SERVER_ERROR;
if (error == LoginProtocol.Error.CONSENT_DENIED) {
String verifiedUserCode = authSession.getClientNote(DeviceGrantType.OAUTH2_DEVICE_VERIFIED_USER_CODE);
OAuth2DeviceTokenStoreProvider store = session.getProvider(OAuth2DeviceTokenStoreProvider.class);
if (!store.deny(realm, verifiedUserCode)) {
// Already expired and removed in the store
errorType = OAuthErrorException.EXPIRED_TOKEN;
} else {
errorType = OAuthErrorException.ACCESS_DENIED;
}
}
return Response.status(302).location(uriBuilder.queryParam(OAuth2Constants.ERROR, errorType).build(realm.getName())).build();
}
use of org.keycloak.models.KeycloakUriInfo in project keycloak by keycloak.
the class DeviceGrantType method approveOAuth2DeviceAuthorization.
public static Response approveOAuth2DeviceAuthorization(AuthenticationSessionModel authSession, AuthenticatedClientSessionModel clientSession, KeycloakSession session) {
KeycloakContext context = session.getContext();
RealmModel realm = context.getRealm();
KeycloakUriInfo uriInfo = context.getUri();
UriBuilder uriBuilder = DeviceGrantType.oauth2DeviceVerificationCompletedUrl(uriInfo);
String verifiedUserCode = authSession.getClientNote(DeviceGrantType.OAUTH2_DEVICE_VERIFIED_USER_CODE);
String userSessionId = clientSession.getUserSession().getId();
OAuth2DeviceTokenStoreProvider store = session.getProvider(OAuth2DeviceTokenStoreProvider.class);
if (!store.approve(realm, verifiedUserCode, userSessionId, null)) {
// Already expired and removed in the store
return Response.status(302).location(uriBuilder.queryParam(OAuth2Constants.ERROR, OAuthErrorException.EXPIRED_TOKEN).build(realm.getName())).build();
}
// Now, remove the verified user code
store.removeUserCode(realm, verifiedUserCode);
return Response.status(302).location(uriBuilder.build(realm.getName())).build();
}
use of org.keycloak.models.KeycloakUriInfo in project keycloak by keycloak.
the class NoCookieFlowRedirectAuthenticator method authenticate.
@Override
public void authenticate(AuthenticationFlowContext context) {
HttpRequest httpRequest = context.getHttpRequest();
// only do redirects for GET requests
if (HttpMethod.GET.equalsIgnoreCase(httpRequest.getHttpMethod())) {
KeycloakUriInfo uriInfo = context.getSession().getContext().getUri();
if (!uriInfo.getQueryParameters().containsKey(LoginActionsService.AUTH_SESSION_ID)) {
Response response = Response.status(302).header(HttpHeaders.LOCATION, context.getRefreshUrl(true)).build();
context.challenge(response);
return;
}
}
context.success();
}
use of org.keycloak.models.KeycloakUriInfo in project keycloak by keycloak.
the class FreeMarkerEmailTemplateProvider method addLinkInfoIntoAttributes.
/**
* Add link info into template attributes.
*
* @param link to add
* @param expirationInMinutes to add
* @param attributes to add link info into
*/
protected void addLinkInfoIntoAttributes(String link, long expirationInMinutes, Map<String, Object> attributes) throws EmailException {
attributes.put("link", link);
attributes.put("linkExpiration", expirationInMinutes);
KeycloakUriInfo uriInfo = session.getContext().getUri();
URI baseUri = uriInfo.getBaseUri();
try {
Locale locale = session.getContext().resolveLocale(user);
attributes.put("linkExpirationFormatter", new LinkExpirationFormatterMethod(getTheme().getMessages(locale), locale));
attributes.put("url", new UrlBean(realm, getTheme(), baseUri, null));
} catch (IOException e) {
throw new EmailException("Failed to template email", e);
}
}
use of org.keycloak.models.KeycloakUriInfo in project keycloak by keycloak.
the class DefaultKeycloakContext method getUri.
@Override
public KeycloakUriInfo getUri(UrlType type) {
if (uriInfo == null || !uriInfo.containsKey(type)) {
if (uriInfo == null) {
uriInfo = new HashMap<>();
}
UriInfo originalUriInfo = getContextObject(UriInfo.class);
uriInfo.put(type, new KeycloakUriInfo(session, type, originalUriInfo));
}
return uriInfo.get(type);
}
Aggregations