-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Moving logic from templates to libs #2989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 14 commits
b4e1769
8b708bb
49d979c
a352e57
97a6838
121901f
4e248ae
ac9d038
3840e58
db8aaeb
ac55723
6dfc790
7a84ae8
e8c955a
f0cfe95
2f77c1c
36b720c
083fecb
9a70244
b450ef2
00e6fbf
90eab52
6b6b2f7
3c818cd
7e76f65
43aaac5
1073098
828b096
aa05550
c4099d5
82f258c
c3454d7
22958f5
9f3a53a
a06e101
1e1d36c
190e789
fb548b0
48dfe49
58fe09a
bd54fb4
ef0182b
8851649
9fc9e17
8a4ce86
a88c972
5bd2680
4f0a8e7
211a04b
03066ee
ae1255b
b9ace98
f50e54b
2478372
cd5347c
438314a
10803d4
52fe7f2
f2df493
b234395
669faca
4e6ddbb
5f3078e
b0417a3
a695db1
cd6940b
5771e1f
4b5a1c7
133e837
bcab437
f1a21e0
563c00c
7c08e2d
e2d5eda
12b925a
0fae11c
ac02cca
6ecacc3
075cc77
1587964
279d1b4
38fdbe0
0bec41e
68a4035
500f574
2dc8399
97f1a49
d07b368
e4eb6dc
e27c122
4a92a58
f976fd3
2b20ffe
8221ba4
5624759
07b4e7b
9b49e2b
b2668fe
aef32fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| packages | ||
| Generator/libs/*.tgz | ||
|
||
|
infomiho marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,15 @@ | ||
| import * as jwt from 'oslo/jwt' | ||
| import { config } from 'wasp/server' | ||
| import { createCreateJWT, createValidateJWT } from "@wasp.sh/libs-auth"; | ||
|
|
||
| const JWT_SECRET = new TextEncoder().encode(config.auth.jwtSecret) | ||
| const JWT_ALGORITHM = 'HS256' | ||
| import { config } from "wasp/server"; | ||
|
|
||
| const JWT_SECRET = new TextEncoder().encode(config.auth.jwtSecret); | ||
| const JWT_ALGORITHM = "HS256"; | ||
|
|
||
| // PRIVATE API | ||
| export function createJWT( | ||
| data: Parameters<typeof jwt.createJWT>[2], | ||
| options: Parameters<typeof jwt.createJWT>[3], | ||
| ): Promise<string> { | ||
| return jwt.createJWT(JWT_ALGORITHM, JWT_SECRET, data, options) | ||
| } | ||
| export const createJWT = createCreateJWT(JWT_SECRET, JWT_ALGORITHM); | ||
infomiho marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
infomiho marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // PRIVATE API | ||
| export async function validateJWT<Payload>(token: string): Promise<Payload> { | ||
| const { payload } = await jwt.validateJWT(JWT_ALGORITHM, JWT_SECRET, token) | ||
| return payload as Payload | ||
| } | ||
| export const validateJWT = createValidateJWT(JWT_SECRET, JWT_ALGORITHM); | ||
|
|
||
| // PRIVATE API | ||
| export { TimeSpan } from 'oslo' | ||
| export { TimeSpan } from "@wasp.sh/libs-auth"; | ||
infomiho marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,36 +1 @@ | ||
| import { hash, verify, Version, type Options } from "@node-rs/argon2"; | ||
|
|
||
| // The options are the same as the ones used in the oslo/password library | ||
| const hashingOptions: Options = { | ||
| memoryCost: 19456, | ||
| timeCost: 2, | ||
| outputLen: 32, | ||
| parallelism: 1, | ||
| version: Version.V0x13, | ||
| }; | ||
|
|
||
| // PRIVATE API | ||
| export async function hashPassword(password: string): Promise<string> { | ||
| return hash(normalizePassword(password), hashingOptions); | ||
| } | ||
|
|
||
| // PRIVATE API | ||
| export async function verifyPassword( | ||
| hashedPassword: string, | ||
| password: string | ||
| ): Promise<void> { | ||
| const validPassword = await verify( | ||
| hashedPassword, | ||
| normalizePassword(password), | ||
| hashingOptions | ||
| ); | ||
| if (!validPassword) { | ||
| throw new Error("Invalid password"); | ||
| } | ||
| } | ||
|
|
||
| // We are normalising the password to ensure that the password is always hashed in the same way | ||
| // We have the same normalising process as oslo/password did in the past | ||
| function normalizePassword(password: string): string { | ||
| return password.normalize("NFKC"); | ||
| } | ||
| export { hashPassword, verifyPassword } from "@wasp.sh/libs-auth"; | ||
infomiho marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,13 @@ | ||
| import { parseCookies } from "@wasp.sh/libs-auth"; | ||
|
||
| import { | ||
| Request as ExpressRequest, | ||
| Response as ExpressResponse, | ||
| } from 'express'; | ||
| import { parseCookies } from 'oslo/cookie'; | ||
| } from "express"; | ||
|
|
||
| import type { ProviderConfig } from 'wasp/auth/providers/types'; | ||
| import { config } from 'wasp/server'; | ||
| import type { ProviderConfig } from "wasp/auth/providers/types"; | ||
|
||
| import { config } from "wasp/server"; | ||
|
|
||
| import type { OAuthStateFieldName } from './state'; | ||
| import type { OAuthStateFieldName } from "./state"; | ||
|
|
||
| export function setOAuthCookieValue( | ||
| provider: ProviderConfig, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.