Skip to content

Browser-Based Apps with a Backend support #9299

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

Closed
iilkevych opened this issue Dec 18, 2020 · 1 comment
Closed

Browser-Based Apps with a Backend support #9299

iilkevych opened this issue Dec 18, 2020 · 1 comment
Assignees
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) status: invalid An issue that we don't feel is valid

Comments

@iilkevych
Copy link

iilkevych commented Dec 18, 2020

Summary
Browser-Based App is JavaScript app with Spring boot backend.
https://tools.ietf.org/html/draft-ietf-oauth-browser-based-apps-07 - section 6.2
https://www.oauth.com/oauth2-servers/single-page-apps/

The best explanation of the problem is here:
#6638 (comment)

It seems there was attempt to fix it here:
#6812
and here
#8118 - WebFlux

Two more requests for this enhancement and attempts to resole it:
#9266
#8950

three more very closely related issues:
#7586
#6802
#4968 - httpBasic() can not be combined with oauth2Login() but it can be combined with formLogin()

Expected Behavior
HTML - 302
REST - 401

Current Behavior
HTML - 302
REST - 302

Context

I will write test to make sure that formLogin() works with oauth2Login() in WebFlux.

JavaScript should get 401 if it sends unauthenticated request.
If there is more then one client registration or formLogin() - response should contain location header with /login
If there is only one registration - response should contain location header with /oauth2/authorization/{registrationId}

Then JavaScript will redirect browser to location from response header. After successful login oauth2Login() should redirect browser to /. Javascript will be loaded in browser again and browser will have active http only session with Spring Boot to access API.

@jgrandja @rwinch @jzheaux what do you think?

@iilkevych iilkevych added status: waiting-for-triage An issue we've not yet triaged type: enhancement A general enhancement labels Dec 18, 2020
@jgrandja
Copy link
Contributor

jgrandja commented Jan 4, 2021

@iilkevych The current behaviour for oauth2Login() (Servlet and WebFlux) will return 302 with Location /login (or custom login page) for unauthenticated XHR requests. This behaviour is expected and is specified in these tests:

OAuth2LoginConfigurerTests (Servlet):

public void oauth2LoginWithOneClientConfiguredAndRequestXHRNotAuthenticatedThenDoesNotRedirectForAuthorization()

OAuth2LoginTests (WebFlux):

public void defaultLoginPageWithSingleClientRegistrationAndXhrRequestThenDoesNotRedirectForAuthorization() {

As per your suggestion:

If there is more then one client registration or formLogin() - response should contain location header with /login

If there is only one registration - response should contain location header with /oauth2/authorization/{registrationId}

I don't feel this makes sense to return a different Location header depending if there is one client registered compared to more than one registered.

Then JavaScript will redirect browser to location from response header.

The redirect to /login is the current behaviour and the JavaScript client cannot perform the redirect to /oauth2/authorization/{registrationId} since this will trigger another redirect to the provider login page and ultimately fail on the CORS request.

I hope this makes sense? I'm going to close this issue as the current behaviour works as designed.

@jgrandja jgrandja closed this as completed Jan 4, 2021
@jgrandja jgrandja self-assigned this Jan 4, 2021
@jgrandja jgrandja added in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged type: enhancement A general enhancement labels Jan 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

2 participants