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

filters/auth: add login redirect stub support #3028

Merged
merged 1 commit into from
Apr 22, 2024

Conversation

AlexanderYastrebov
Copy link
Member

For single page applications user may want to return javascript stub that stores location hash into localstorage and then redirects user to the authorization url.

@AlexanderYastrebov AlexanderYastrebov added wip work in progress major moderate risk, for example new API, small filter changes that have no risk like refactoring or logs labels Apr 19, 2024
AlexanderYastrebov added a commit to zalando-incubator/kubernetes-on-aws that referenced this pull request Apr 19, 2024
Signed-off-by: Alexander Yastrebov <[email protected]>
@AlexanderYastrebov AlexanderYastrebov force-pushed the filters/auth/grant-login-redirect branch 3 times, most recently from 4bf22a9 to 387cbf3 Compare April 19, 2024 15:21
@AlexanderYastrebov AlexanderYastrebov removed the wip work in progress label Apr 19, 2024
@AlexanderYastrebov AlexanderYastrebov marked this pull request as ready for review April 19, 2024 15:22
@AlexanderYastrebov AlexanderYastrebov marked this pull request as draft April 19, 2024 15:24
For single page applications user may want to return javascript stub
that stores location hash into localstorage and then redirects
user to the authorization url.

Signed-off-by: Alexander Yastrebov <[email protected]>
@AlexanderYastrebov AlexanderYastrebov marked this pull request as ready for review April 19, 2024 15:35
`)
-> oauthGrant()
-> "http://localhost:9090";
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and now this inside a yaml :D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its fine actually:

  routes:
    - pathSubtree: /
      filters:
        - |
          annotate("oauthGrant.loginRedirectStub", `
            <!doctype html>
            <html lang="en">
              <head>
                <title>Redirecting...</title>
                <script>
                  if (window.location.hash !== null) {
                    localStorage.setItem('original-location-hash', window.location.hash);
                  }
                  window.location.replace('{{authCodeURL}}');
                </script>
              </head>
            </html>
          `)
        - oauthGrant()
        - |
          inlineContent(`
            <!doctype html>
            <html lang="en">
              <head>
                <title>Hello world</title>
              </head>
              <body>
                <p id="hello">Hello world</p>

                <script>
                  const hash = localStorage.getItem('original-location-hash');
                  if (hash !== null) {
                    window.location.hash = hash;
                    localStorage.removeItem('original-location-hash');
                  }
                  document.getElementById('hello').innerText = 'Page: ' + window.location.hash;
                </script>
              </body>
            </html>
          `)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤯

@szuecs
Copy link
Member

szuecs commented Apr 19, 2024

👍

@macedigital
Copy link
Member

Wow, thanks for implementing this so quickly 🚀

@macedigital
Copy link
Member

👍

@AlexanderYastrebov AlexanderYastrebov merged commit 2a5d037 into master Apr 22, 2024
14 checks passed
@AlexanderYastrebov AlexanderYastrebov deleted the filters/auth/grant-login-redirect branch April 22, 2024 08:14
AlexanderYastrebov added a commit to zalando-incubator/kubernetes-on-aws that referenced this pull request Apr 22, 2024
[Changes](zalando/skipper@v0.21.54...v0.21.61)

* [build(deps): bump amazonlinux from `ef9435f` to `5478f82` in /fuzz](zalando/skipper#3031)
* [build(deps): bump actions/upload-artifact from 4.3.1 to 4.3.2](zalando/skipper#3033)
* [build(deps): bump actions/checkout from 4.1.2 to 4.1.3](zalando/skipper#3032)
* [build(deps): bump github.com/miekg/dns from 1.1.58 to 1.1.59](zalando/skipper#3030)
* [proxy: support configurable metrics](zalando/skipper#3027)
* [filters/auth: add login redirect stub support](zalando/skipper#3028)
* [filters: move annotate into own package](zalando/skipper#3023)
* [filters/auth: add jwtMetrics](zalando/skipper#3020)
* [filters/builtin: add annotate filter](zalando/skipper#3022)

Signed-off-by: Alexander Yastrebov <[email protected]>
AlexanderYastrebov added a commit to zalando-incubator/kubernetes-on-aws that referenced this pull request Apr 22, 2024
[Changes](zalando/skipper@v0.21.54...v0.21.61)

* `build(deps): bump amazonlinux from `ef9435f` to `5478f82` in /fuzz` zalando/skipper#3031
* `build(deps): bump actions/upload-artifact from 4.3.1 to 4.3.2` zalando/skipper#3033
* `build(deps): bump actions/checkout from 4.1.2 to 4.1.3` zalando/skipper#3032
* `build(deps): bump github.com/miekg/dns from 1.1.58 to 1.1.59` zalando/skipper#3030
* `proxy: support configurable metrics` zalando/skipper#3027
* `filters/auth: add login redirect stub support` zalando/skipper#3028
* `filters: move annotate into own package` zalando/skipper#3023
* `filters/auth: add jwtMetrics` zalando/skipper#3020
* `filters/builtin: add annotate filter` zalando/skipper#3022

Signed-off-by: Alexander Yastrebov <[email protected]>
AlexanderYastrebov added a commit that referenced this pull request Jul 22, 2024
Login redirect stub introduced by #3028 uses `{{authCodeURL}}` placeholder
that is a valid mustache template and hence inconvenient to use from
mustache templates.

This change adds a second `{authCodeURL}` placeholder.

Signed-off-by: Alexander Yastrebov <[email protected]>
AlexanderYastrebov added a commit that referenced this pull request Jul 22, 2024
Login redirect stub introduced by #3028 uses `{{authCodeURL}}` placeholder
that is a valid mustache template and hence inconvenient to use from
mustache templates.

This change adds a second `{authCodeURL}` placeholder and
`X-Auth-Code-Url` response header.

Signed-off-by: Alexander Yastrebov <[email protected]>
AlexanderYastrebov added a commit that referenced this pull request Jul 22, 2024
Login redirect stub introduced by #3028 uses `{{authCodeURL}}` placeholder
that is a valid mustache template and hence inconvenient to use from
mustache templates.

This change adds a second `{authCodeURL}` placeholder and
`X-Auth-Code-Url` response header.

Signed-off-by: Alexander Yastrebov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major moderate risk, for example new API, small filter changes that have no risk like refactoring or logs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants