org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest Java Examples

The following examples show how to use org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpCookieOAuth2AuthorizationRequestRepository.java    From spring-boot-react-blog with Apache License 2.0 6 votes vote down vote up
@Override
public void saveAuthorizationRequest(OAuth2AuthorizationRequest authorizationRequest, HttpServletRequest request, HttpServletResponse response) {
    Assert.notNull(request, "request cannot be null");
    Assert.notNull(response, "response cannot be null");

    if (authorizationRequest == null) {
        CookieUtils.deleteCookie(request, response, OAUTH2_AUTHORIZATION_REQUEST_COOKIE_NAME);
        CookieUtils.deleteCookie(request, response, REDIRECT_URI_PARAM_COOKIE_NAME);
        return;
    }

    CookieUtils.addCookie(response, OAUTH2_AUTHORIZATION_REQUEST_COOKIE_NAME, CookieUtils.serialize(authorizationRequest), cookieExpireSeconds);
    String redirectUriAfterLogin = request.getParameter(REDIRECT_URI_PARAM_COOKIE_NAME);
    if (StringUtils.isNotBlank(redirectUriAfterLogin)) {
        CookieUtils.addCookie(response, REDIRECT_URI_PARAM_COOKIE_NAME, redirectUriAfterLogin, cookieExpireSeconds);
    }
}
 
Example #2
Source File: CustomAuthorizationRequestResolver.java    From messaging-app with Apache License 2.0 5 votes vote down vote up
@Override
public OAuth2AuthorizationRequest resolve(HttpServletRequest request, String clientRegistrationId) {
	OAuth2AuthorizationRequest authorizationRequest =
			this.defaultAuthorizationRequestResolver.resolve(request, clientRegistrationId);
	if (authorizationRequest != null) {
		return customAuthorizationRequest(authorizationRequest);
	}
	return authorizationRequest;
}
 
Example #3
Source File: CustomAuthorizationRequestResolver.java    From tutorials with MIT License 5 votes vote down vote up
private OAuth2AuthorizationRequest customizeAuthorizationRequest(OAuth2AuthorizationRequest req) {
    Map<String,Object> extraParams = new HashMap<String,Object>();
    extraParams.putAll(req.getAdditionalParameters()); //VIP note
    extraParams.put("test", "extra");
    System.out.println("here =====================");
    return OAuth2AuthorizationRequest.from(req).additionalParameters(extraParams).build();
}
 
Example #4
Source File: CustomAuthorizationRequestResolver.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public OAuth2AuthorizationRequest resolve(HttpServletRequest request, String clientRegistrationId) {
    OAuth2AuthorizationRequest req = defaultResolver.resolve(request, clientRegistrationId);
    if(req != null){
        req = customizeAuthorizationRequest(req);
    }
    return req;
}
 
Example #5
Source File: CustomAuthorizationRequestResolver.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public OAuth2AuthorizationRequest resolve(HttpServletRequest request) {
    OAuth2AuthorizationRequest req = defaultResolver.resolve(request);
    if(req != null){
        req = customizeAuthorizationRequest(req);
    }
    return req;
}
 
Example #6
Source File: HttpCookieOAuth2AuthorizationRequestRepository.java    From training with MIT License 5 votes vote down vote up
@Override
public void saveAuthorizationRequest(OAuth2AuthorizationRequest authorizationRequest, HttpServletRequest request, HttpServletResponse response) {
    if (authorizationRequest == null) {
        CookieUtils.deleteCookie(request, response, OAUTH2_AUTHORIZATION_REQUEST_COOKIE_NAME);
        CookieUtils.deleteCookie(request, response, REDIRECT_URI_PARAM_COOKIE_NAME);
        return;
    }

    CookieUtils.addCookie(response, OAUTH2_AUTHORIZATION_REQUEST_COOKIE_NAME, CookieUtils.serialize(authorizationRequest), cookieExpireSeconds);
    String redirectUriAfterLogin = request.getParameter(REDIRECT_URI_PARAM_COOKIE_NAME);
    if (StringUtils.isNotBlank(redirectUriAfterLogin)) {
        CookieUtils.addCookie(response, REDIRECT_URI_PARAM_COOKIE_NAME, redirectUriAfterLogin, cookieExpireSeconds);
    }
}
 
Example #7
Source File: HttpCookieOAuth2AuthorizationRequestRepository.java    From spring-boot-react-blog with Apache License 2.0 5 votes vote down vote up
@Override
public OAuth2AuthorizationRequest removeAuthorizationRequest(HttpServletRequest request) {
    Assert.notNull(request, "request cannot be null");
    /*
        Ideally, the saved OAuth2AuthorizationRequest should be removed in this method.

        Since we're saving the OAuth2AuthorizationRequest in cookies, we need access to the HttpServletResponse to clear them.
        But that is not passed to this method.

        Therefore, We'll clear the cookies in Oauth2AuthenticationSuccessHandler instead.
    */
    return loadAuthorizationRequest(request);
}
 
Example #8
Source File: HttpCookieOAuth2AuthorizationRequestRepository.java    From spring-boot-react-blog with Apache License 2.0 5 votes vote down vote up
@Override
public OAuth2AuthorizationRequest loadAuthorizationRequest(HttpServletRequest request) {
    Assert.notNull(request, "request cannot be null");
    return CookieUtils.getCookie(request, OAUTH2_AUTHORIZATION_REQUEST_COOKIE_NAME)
            .map(cookie -> CookieUtils.deserialize(cookie, OAuth2AuthorizationRequest.class))
            .orElse(null);
}
 
Example #9
Source File: CustomAuthorizationRequestResolver.java    From messaging-app with Apache License 2.0 5 votes vote down vote up
private OAuth2AuthorizationRequest customAuthorizationRequest(OAuth2AuthorizationRequest authorizationRequest) {
	Set<String> scopes = new LinkedHashSet<>(authorizationRequest.getScopes());
	scopes.add("contacts");
	return OAuth2AuthorizationRequest.from(authorizationRequest)
			.scopes(scopes)
			.build();
}
 
Example #10
Source File: CustomAuthorizationRequestResolver.java    From messaging-app with Apache License 2.0 5 votes vote down vote up
@Override
public OAuth2AuthorizationRequest resolve(HttpServletRequest request) {
	OAuth2AuthorizationRequest authorizationRequest =
			this.defaultAuthorizationRequestResolver.resolve(request);
	if (authorizationRequest != null) {
		return customAuthorizationRequest(authorizationRequest);
	}
	return authorizationRequest;
}
 
Example #11
Source File: WebSecurityConfig.java    From spring-boot-react-blog with Apache License 2.0 4 votes vote down vote up
private AuthorizationRequestRepository<OAuth2AuthorizationRequest> cookieAuthorizationRequestRepository() {
    return new HttpCookieOAuth2AuthorizationRequestRepository();
}
 
Example #12
Source File: HttpCookieOAuth2AuthorizationRequestRepository.java    From training with MIT License 4 votes vote down vote up
@Override
public OAuth2AuthorizationRequest loadAuthorizationRequest(HttpServletRequest request) {
    return CookieUtils.getCookie(request, OAUTH2_AUTHORIZATION_REQUEST_COOKIE_NAME)
            .map(cookie -> CookieUtils.deserialize(cookie, OAuth2AuthorizationRequest.class))
            .orElse(null);
}
 
Example #13
Source File: HttpCookieOAuth2AuthorizationRequestRepository.java    From training with MIT License 4 votes vote down vote up
@Override
public OAuth2AuthorizationRequest removeAuthorizationRequest(HttpServletRequest request) {
    return this.loadAuthorizationRequest(request);
}
 
Example #14
Source File: CustomAuthorizationRequestResolver.java    From tutorials with MIT License 4 votes vote down vote up
private OAuth2AuthorizationRequest customizeAuthorizationRequest1(OAuth2AuthorizationRequest req) {
    return OAuth2AuthorizationRequest.from(req).state("xyz").build();
}
 
Example #15
Source File: CustomAuthorizationRequestResolver.java    From tutorials with MIT License 4 votes vote down vote up
private OAuth2AuthorizationRequest customizeOktaReq(OAuth2AuthorizationRequest req) {
    Map<String,Object> extraParams = new HashMap<String,Object>();
    extraParams.putAll(req.getAdditionalParameters()); 
    extraParams.put("idp", "https://idprovider.com");
    return OAuth2AuthorizationRequest.from(req).additionalParameters(extraParams).build();
}
 
Example #16
Source File: SecurityConfig.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
public AuthorizationRequestRepository<OAuth2AuthorizationRequest> authorizationRequestRepository() {
    return new HttpSessionOAuth2AuthorizationRequestRepository();
}
 
Example #17
Source File: CustomRequestSecurityConfig.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
public AuthorizationRequestRepository<OAuth2AuthorizationRequest> authorizationRequestRepository() {
    return new HttpSessionOAuth2AuthorizationRequestRepository();
}