-
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.
- Loading branch information
Showing
6 changed files
with
18 additions
and
14 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
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
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,17 +1,20 @@ | ||
import jose from "jose"; | ||
import * as jose from "jose"; | ||
|
||
export const generateJwt = async ( | ||
channelId: string, | ||
secretKey: string, | ||
): Promise<string> => { | ||
if (secretKey === "") { | ||
return ""; | ||
} | ||
const header = { alg: "HS256", typ: "JWT" }; | ||
const payload = { | ||
// 30 秒後に有効期限切れ | ||
exp: Math.floor(Date.now() / 1000) + 30, | ||
channel_id: channelId, | ||
}; | ||
return await new jose.SignJWT(payload) | ||
.setProtectedHeader(header) | ||
.setIssuedAt() | ||
.sign(new TextEncoder().encode(secretKey)); | ||
return ( | ||
new jose.SignJWT({ | ||
channel_id: channelId, | ||
}) | ||
.setProtectedHeader(header) | ||
// 30 秒後に有効期限切れ | ||
.setExpirationTime("30s") | ||
.sign(new TextEncoder().encode(secretKey)) | ||
); | ||
}; |