Skip to content

Commit

Permalink
Add support for state parameter (take two)
Browse files Browse the repository at this point in the history
The previous implementation incorrectly took state from the token
claims, but it is returned as a normal query parameter to the callback,
so outside the scope of client libraries.
  • Loading branch information
stephank committed Dec 1, 2023
1 parent d731cd5 commit 5b1e389
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client-tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ rl.on("line", (line) => {
wrap(async () => cmd[1]);
break;
case "auth":
wrap(async () => client.authenticate(cmd[1]));
wrap(async () => client.authenticate(cmd[1], cmd[2]));
break;
case "verify":
wrap(async () => client.verify(cmd[1]));
Expand Down
10 changes: 8 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ export default class PortierClient {
* Start authentication of an email address.
*
* Returns a URL to redirect the user agent to.
*
* This method rethrows any failures from the store.
*/
async authenticate(email: string): Promise<string> {
async authenticate(email: string, state?: string): Promise<string> {
const discovery = await this.fetchDiscovery();
const nonce = await this.store.createNonce(email);

Expand All @@ -95,14 +97,18 @@ export default class PortierClient {
response_mode: this.responseMode,
client_id: this._clientId,
redirect_uri: this._redirectUri,
state,
});
return `${discovery.authorization_endpoint}?${params}`;
}

/**
* Verify a token received on our `redirectUri`.
*
* Returns the email address, or throws if invalid.
* On success, returns the verified email address.
*
* If the token is invalid, this method throws. This method also rethrows any
* failures from the store.
*/
async verify(token: string): Promise<string> {
const discovery = await this.fetchDiscovery();
Expand Down

0 comments on commit 5b1e389

Please sign in to comment.