Skip to content
This repository was archived by the owner on Jan 24, 2019. It is now read-only.
This repository was archived by the owner on Jan 24, 2019. It is now read-only.

Question: Intended Flow and Configuration for Single Page Apps? #571

@blaskovicz

Description

@blaskovicz

Use-Case

I have a single-page react app that needs to authenticate against the Github API, and then, subsequently, use the access_token to access said api. My question: is this an intended use case, and, if so, what should the configuration look like?

Typically, these type of apps can easily authenticate with an implicit-grant; this yields them the access-token, client-side, as part of the final redirect uri which can be parsed and used.

Config and Observations

I set up oauth2_proxy in two ways and observed the following..

  1. config: nginx: proxy_pass everything to oauth2_proxy; oauth2_proxy: set upstream to spa, -set-xauthrequest=true, -pass-access-token=true, -redirect-url=/oauth2/callback.
    observation: this sets the X-Auth-Request-Access-Token head on the request made to the spa, but I would have to configure that app to inject the header back into the response / html. Also, this means all requests to the spa are proxying through the oauth2_proxy

  2. config: nginx: proxy_pass /oauth2/ and /oauth2/auth to oauth2_proxy, / to spa with auth_request set to /oauth2/auth, error_page 401 = /oauth2/sign_in, and add_header set-cookie $auth_cookie ($upstream_http_set_cookie); oauth2_proxy has no upstream, -set-xauthrequest=true, -redirect-url=/oauth2/callback.
    observation: this performs auth requests when the user isn't authenticated, and then ultimately sets the cookie (default _oauth2_proxy) such that it's visable to the spa. The problem is that when the cookie base64 decoded, no access_token is present.

Possible Solutions

If the solution isn't as simple as adjusting my config, I'm able to help with updating the proxy code. Here are a few solutions I can think of.

  • add an option to oauth2_proxy which could allow encoding the access_token, refresh_token, etc into the cookie returned from the /oauth2/callback endpoint
  • add a route to oauth2_proxy for GET /oauth2/token which could return the current json representing the access_token, refresh_token, expires, etc based on the current session.
  • In config option 1, I could have the backend server inject request headers into the response body (cookies, or javascript).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions