-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from markusahlstrand/silent-auth
add silent auth for the code flow
- Loading branch information
Showing
17 changed files
with
153 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
# @authhero/demo | ||
|
||
## 0.2.6 | ||
|
||
### Patch Changes | ||
|
||
- Updated dependencies | ||
- [email protected] | ||
- @authhero/kysely-adapter@0.24.2 | ||
|
||
## 0.2.5 | ||
|
||
### Patch Changes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# @authhero/adapter-interfaces | ||
|
||
## 0.29.0 | ||
|
||
### Minor Changes | ||
|
||
- add silent tokens | ||
|
||
## 0.28.0 | ||
|
||
### Minor Changes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "authhero", | ||
"version": "0.16.0", | ||
"version": "0.17.0", | ||
"files": [ | ||
"dist" | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export const JWKS_CACHE_TIMEOUT_IN_SECONDS = 60 * 5; // 5 minutes | ||
export const SILENT_AUTH_MAX_AGE = 30 * 24 * 60 * 60; // 30 days | ||
export const SILENT_COOKIE_NAME = "auth-token"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import { testClient } from "hono/testing"; | |
import { getTestServer } from "../../helpers/test-server"; | ||
import { parseJWT } from "oslo/jwt"; | ||
import { computeCodeChallenge } from "../../../src/utils/crypto"; | ||
import { CodeChallengeMethod } from "@authhero/adapter-interfaces"; | ||
|
||
describe("token", () => { | ||
describe("client_credentials", () => { | ||
|
@@ -446,6 +447,62 @@ describe("token", () => { | |
|
||
expect(secondResponse.status).toBe(403); | ||
}); | ||
|
||
it("should set a silent authentication token", async () => { | ||
const { oauthApp, env } = await getTestServer(); | ||
const client = testClient(oauthApp, env); | ||
|
||
// Create the login session and code | ||
const loginSesssion = await env.data.logins.create("tenantId", { | ||
expires_at: new Date(Date.now() + 1000 * 60 * 5).toISOString(), | ||
authParams: { | ||
client_id: "clientId", | ||
username: "[email protected]", | ||
scope: "", | ||
audience: "http://example.com", | ||
redirect_uri: "http://example.com/callback", | ||
}, | ||
}); | ||
|
||
await env.data.codes.create("tenantId", { | ||
code_type: "authorization_code", | ||
user_id: "email|userId", | ||
code_id: "123456", | ||
login_id: loginSesssion.login_id, | ||
expires_at: new Date(Date.now() + 1000 * 60 * 5).toISOString(), | ||
}); | ||
|
||
const response = await client.oauth.token.$post( | ||
{ | ||
form: { | ||
grant_type: "authorization_code", | ||
code: "123456", | ||
redirect_uri: "http://example.com/callback", | ||
client_id: "clientId", | ||
client_secret: "clientSecret", | ||
}, | ||
}, | ||
{ | ||
headers: { | ||
"tenant-id": "tenantId", | ||
}, | ||
}, | ||
); | ||
|
||
expect(response.status).toBe(200); | ||
const body = await response.json(); | ||
|
||
const accessToken = parseJWT(body.access_token); | ||
|
||
if (!accessToken || !("sid" in accessToken.payload)) { | ||
throw new Error("sid is missing"); | ||
} | ||
|
||
const cookie = response.headers.get("set-cookie"); | ||
expect(cookie).toBe( | ||
`tenantId-auth-token=${accessToken?.payload.sid}; HttpOnly; Max-Age=604800; Path=/; SameSite=None; Secure`, | ||
); | ||
}); | ||
}); | ||
|
||
describe("authorization_code with PKCE", () => { | ||
|
@@ -465,7 +522,7 @@ describe("token", () => { | |
scope: "", | ||
audience: "http://example.com", | ||
code_challenge: codeChallenge, | ||
code_challenge_method: "plain", | ||
code_challenge_method: CodeChallengeMethod.Plain, | ||
}, | ||
}); | ||
|
||
|
@@ -523,7 +580,7 @@ describe("token", () => { | |
scope: "", | ||
audience: "http://example.com", | ||
code_challenge: await computeCodeChallenge(codeChallenge, "S256"), | ||
code_challenge_method: "S256", | ||
code_challenge_method: CodeChallengeMethod.S256, | ||
}, | ||
}); | ||
|
||
|
@@ -581,7 +638,7 @@ describe("token", () => { | |
scope: "", | ||
audience: "http://example.com", | ||
code_challenge: codeChallenge, | ||
code_challenge_method: "plain", | ||
code_challenge_method: CodeChallengeMethod.Plain, | ||
}, | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters