Skip to content

Commit

Permalink
fix: send /authorize params through url
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsorban44 committed Feb 1, 2021
1 parent 214b22e commit 30c6d63
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ const _useSessionHook = (session) => {
// Client side method
export const signIn = async (provider, args = {}, authorizationParams = {}) => {
const baseUrl = _apiBaseUrl()
const callbackUrl = args.callbackUrl ?? window.location
const callbackUrl = args?.callbackUrl ?? window.location
const providers = await getProviders()

// Redirect to sign in page if no valid provider specified
Expand All @@ -256,14 +256,13 @@ export const signIn = async (provider, args = {}, authorizationParams = {}) => {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: _encodedForm({
...args,
authorizationParams,
csrfToken: await getCsrfToken(),
callbackUrl: callbackUrl,
json: true
})
}
const res = await fetch(signInUrl, fetchOptions)
const _signInUrl = `${signInUrl}?${_encodedForm(authorizationParams)}`
const res = await fetch(_signInUrl, fetchOptions)
const data = await res.json()
window.location = data.url ?? callbackUrl
}
Expand Down
3 changes: 2 additions & 1 deletion src/server/lib/signin/oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ export default async function getAuthorizationUrl (req) {

const client = oAuthClient(provider)
if (provider.version?.startsWith('2.')) {
delete req.query?.nextauth
// Handle OAuth v2.x
let url = client.getAuthorizeUrl({
...provider.authorizationParams,
...req.body.authorizationParams,
...req.query,
redirect_uri: provider.callbackUrl,
scope: provider.scope
})
Expand Down
4 changes: 2 additions & 2 deletions www/docs/getting-started/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ The URL must be considered valid by the [redirect callback handler](/configurati

It is also possible to pass additional parameters to the `/authorize` endpoint through the third argument of `signIn()`.

See the [Authorization Request OIDC spec](https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest) for some ideas.
See the [Authorization Request OIDC spec](https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest) for some ideas. (These are not the only possible ones, all parameters will be forwarded)

e.g.

Expand All @@ -226,7 +226,7 @@ You can also set these parameters through [`provider.authorizationParams`](/conf
:::

:::note
The following parameters are always overridden: `redirect_uri`, `scope`, `state`
The following parameters are always overridden server-side: `redirect_uri`, `scope`, `state`
:::

---
Expand Down

0 comments on commit 30c6d63

Please sign in to comment.