Skip to content
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

Add example: a single-page app #17

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open

Add example: a single-page app #17

wants to merge 2 commits into from

Conversation

oneb
Copy link

@oneb oneb commented Mar 31, 2023

This adds an example that illustrates authentication for a single-page app.

With the current example in example/Auth.hs, when you click the login link, you leave the current page and lose all of its state. With this new example in example/AuthSinglePageApp.hs, the login page instead opens in a new tab and the original tab stays intact. Once the login process is complete a WebSocket informs the original tab that the user has logged in, and the page updates to indicate that.

I mostly added new code, in AuthSinglePageApp.hs, and interfered with the existing code as little as possible.

A new command-line option was added, --single-page-app, which causes the SPA example app in AuthSinglePageApp.hs to be run instead of the existing example app in Auth.hs. Otherwise usage is the same, and if you do not use that option, everything works exactly as before.

So to run the new example, you do:

cd openid-connect
example/make-tls-certs.sh
cabal run example -- -p https://accounts.google.com/.well-known/openid-configuration  -i <client-id> -s <client-secret> --single-page-app

The only difference, compared to how you run the old example in Auth.hs, is that last command line argument.

@pjones
Copy link
Owner

pjones commented Apr 10, 2023

Thank you very much for contributing this example.

I'm leaning towards including it, but I'm also worried that it needlessly complicates the existing example, which is already quite large. Isn't demonstrating how to use OpenID Connect from within a single-page application pretty far out of the scope of this project? Would this content be a better fit for a blog article?

What are your thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants