Skip to content

Commit 2374b18

Browse files
Nick Krulnkrul
authored andcommitted
Allow redirect uri to be specified
1 parent c923e69 commit 2374b18

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

src/App.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const {AuthContext, Authenticated, useToken} = createAuthContext({
1010
clientSecret,
1111
provider,
1212
// tokenEndpoint: 'http://localhost:3020/token' // If token endpoint is not "provider + '/token'"
13+
// redirect_uri: "http://localhost:3001/" // If your redirect_uri is not just back to the current page
1314
})
1415

1516
function ProtectedStuff() {

src/lib/createAuthContext.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export default ({
1414
tokenEndpoint = `${provider}/token`,
1515
storage = sessionStorage,
1616
fetch = window.fetch,
17-
busyIndicator = <>logging in...</>
17+
busyIndicator = <>logging in...</>,
18+
redirect_uri = window.location.toString()
1819
}) => {
1920

2021
const context = createContext({})
@@ -76,7 +77,7 @@ export default ({
7677
const ensureAuthenticated = () => {
7778
const code = getCodeFromLocation({ location: window.location })
7879
if (!token && !code) {
79-
authorize({provider, clientId, scopes})
80+
authorize({provider, clientId, scopes, redirect_uri})
8081
}
8182
}
8283

src/lib/helpers/authorize.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ export default function authorize({
77
provider,
88
clientId,
99
scopes,
10-
storage = sessionStorage
10+
storage = sessionStorage,
11+
redirect_uri
1112
}) {
1213

13-
const redirect_uri = window.location.toString()
14-
1514
const encodedVerifier = base64URLEncode(createCodeVerifier())
1615
storage.setItem(
1716
getEncodedVerifierKey(clientId),

0 commit comments

Comments
 (0)