SohoHouse / nuxt-oauth

Simple OAuth2 integration for your Nuxt app
MIT License
122 stars 27 forks source link

Provide configured oauthHost via $store.state.oauth.host #25

Closed col-panic closed 6 years ago

col-panic commented 6 years ago

I want to re-use the configured host for subsequent initializations of clients. In my special case, the SwaggerClient. For this i propose to add the connected host to $store.state.oauth.host as done by this patch.

samtgarson commented 6 years ago

This is a very special case and I don't think it adds a lot of value to this module.

You can achieve the same effect by redirecting to /auth/login?redirectUrl=X&oauthHost=Y, then in nuxt.config.js:

const { parse } = require('qs')

const extractHostFromURL = url => {
  const { oauthHost } = parse(url.split('?')[1])
  return oauthHost || process.env.OAUTH_HOST
}

module.exports = {
  ...nuxtConfig,
  oauth: {
    oauthHost: req => extractHostFromURL(req.url)
  }
}

As long as you also append &oauthHost=Y to your redirect URL, this will also be picked up upon return from the OAuth provider.

col-panic commented 6 years ago

Whow, nice! thanks a lot for that!!

col-panic commented 6 years ago

I see it works without this - and I even found a solution to auto-initialize a swagger-client (via a nuxt plugin)! It, however, relies on my patch including the host to this.$store.state.oauth.host - could you possibly accept this patch? If yes, there is no further reason for me to keep the fork!

thanks a lot!

samtgarson commented 6 years ago

@col-panic I'm afraid this functionality seems very specific to your use case, and its extra logic that we would have to test and support, and extra surface area to cover for security. Happy to help but if you'd like to have this functionality please use your fork. Thanks!

col-panic commented 6 years ago

Allright, thank you :)

col-panic commented 6 years ago

Unfortunately, your solution does not fully work, as extractHostFromURL is only called once (as the OauthClient is a constant) - seems like I still have to revert to my own fork!