-
Notifications
You must be signed in to change notification settings - Fork 16
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
Mechanism for SPA to discover auth0 login url #151
Comments
I havent created a SPA yet for myself, I have focused on API authentication for now. I should probably create a simple SPA to test how forwardauth + auth0 behaves. ForwardAuth uses the authorization code grant flow from Auth0/OAuth2/OIDC. I need to read up on this to find out if acutally most of the implementation could be done using normal implicit grant flow and possible add eventual missing features to ForwardAuth to support it like the normal authentication code flow for APIs. |
New guidance in using implicit grant https://auth0.com/blog/oauth2-implicit-grant-and-spa/ |
could possibly be the mechanism you are thinking about. |
Awesome! This looks exactly what we need: we're serving our SPA from the same domain as our API. Would you accept a PR if I implemented the following logic:
|
Hm, wouldn't that be exactly how the standard non-API type of URL is handled? |
Non-API URLs return HTTP 307 so browser follows them when it does AJAX requests. It might be ok to return HTTP 302 in all cases (API and non-API), but we might break existing API clients which expect 403. |
The 307 was chosen so that the method would not be changed by the redirect, but when thinking of it, it is probably not a problem because if you want a redirect you want a redirect with GET to Auth0 login anyways. |
So what do you think about this approach? |
We could try changing for 302 Redirect and see how it behaves, especially for AJAX calls. |
I think SPA could do either of those, it is up to SPA to decide. In my case, I'd prefer if I could just open a new window, make user to get new code from auth0, signin with forwardauth to get new token, and then re-try the request which "failed" with 302. Does that make sense? |
Yup, that was the way I was thinking it would work. |
In my case, there isn't. In most cases I can think of, the backend should use |
If you want to have a go at it, create a PR that removes the special
response handling of API types, and both API and normal clients get the
same 302 redirect.
If you have a simple SPA to test with as well, it would be very helpful if
you could contribute it for further development for ajax/spa clients.
And if you want to use the CI/CD I have configured (have a look at the
contribution page) I could add you as a contributor to the repo.
Another question just out of curiosity, what environment do you use?
Kubernetes, standalone docker or something else?
man. 27. jan. 2020 kl. 10:59 skrev Karolis Labrencis <
[email protected]>:
… In my case, there isn't. In most cases I can think of, 303 See Other or 307
Temporary Redirect should be used instead of 302.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#151?email_source=notifications&email_token=AAFNMCSHQVTOO5R2HOGJG6TQ72V7RA5CNFSM4KLMFDP2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJ65WHA#issuecomment-578673436>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFNMCUBMF6QOKYBODSHAZTQ72V7RANCNFSM4KLMFDPQ>
.
|
Alright, I hope to start sometime this week.
I don't have one at the moment, since I'm using my project's SPA to test the flow.
Sure, that would be nice!
Stable version of forwardauth is deployed to my project's GKE clusters. When I want to e2e test changes in Forwardauth (i.e. when I'm developing a PR), I use telepresence to swap real ForwardAuth deployment with one started in my IntelliJ IDEA IDE (on my PC). So the traffic flow looks like this: |
Kool, I added a .editconfig file from my IDEA to the 2.0-rc1 branch. I use default IDEA settings for code style. And also added you as a collaborator to the repo. |
@KarolisL the logic for handling authz and authn is implemented as two state machines, |
yeah. agree, that SPA seems like a good start for a SPA for testing |
I'm interested in following this conversation. I had a similar request for an auth server I author over here: travisghansen/external-auth-server#57 If one has control over the app/SPA I ended up allowing a couple things:
ajax requests currently are determined by:
OR
|
@travisghansen thanx for your feedback, whats your experience of your solution? are you happy and its working fine or would you solve it in another way now in hindsight? |
from what I have thinking is that it would be nice for the client to receive the authentication-url for where to go to do the authentication from the auth-server backend, to be able to redirect the user for authentication in the browser. |
what is the content of the |
@dniel yeah it works great so far. Speaking generally it's main deficiency is you must have control over the SPA which is fine for the use-case but when using 3rd party SPAs you're still kinda stuck. If you control/program/develop the app it's 100% effective. That's exactly what I do is send the authentication URL to the client both in the |
As described in RFC-6750 https://tools.ietf.org/html/rfc6750#section-3 (The OAuth 2.0 Authorization Framework: Bearer Token Usage) the Oauth2 specification has described the proper response from a protected resource server.
other error codes mentioned are invalid_request, invalid_token and insufficient_scope
It also says
A complete error response for a missing scope could be something like.
|
Never read that spec but programmed what I have based on experience and appears to fall in line. I probably should add the error fields though... |
Note the phrase Other auth-param attributes MAY be used as well in the spec. |
Something like
|
It also seems that at least the HTTP/1.1 spec (https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.47) is open using multiple WWW-Authenticate headers, and possibly multiple auth-schemas in one header. Auth-Schemas is extendable so another approach could be to create a custom auth-schema to add along with the standard Bearer. Something like
|
I guess maybe I’m unclear on what you feel is off spec exactly? |
Nothing really :) it seems like both approaches with adding the url to the login server as a custom attribute on the Bearer auth-schema and also the other approach of using a custom auth-schema seems to be perfectly fine in terms of specs. |
Why not use |
do you have an example of syntax? |
Of the header value or a configuration of the auth server? |
From Hypertext Transfer Protocol (HTTP/1.1): Authentication
In the mozilla doc the realm is described as
From what I can see, the realm value should contain a value describing a protected area. |
An example of your realm header value syntax, and also it would be interesting to see a complete example your version of the WWW-Authenticate header. And if you have any examples of other observed services you mentioned, it would be interesting to see how others has implemented the WWW-Authenticate syntax. |
I’ll send over sample when back to my desk, but in short it’s the full authorization code flow redirect URI to the provider. ie: login here URL (not to be confused with the It’s a slightly different flow with the docker client but general principle applies: https://docs.docker.com/registry/spec/auth/token/ Specifically the |
Regarding the Not sure if that makes any sense? A bit rambly :) |
SPAs get HTTP 403 after token expires. This works as expected, but it would be nice if in such case, SPA could open a new window with Auth0 login page. For this to work, we need two things:
Relates to #128
The text was updated successfully, but these errors were encountered: