Skip to content

Commit 437426c

Browse files
committed
feat(oauth-providers): availbility pass state into middlewares
1 parent 88bb116 commit 437426c

File tree

5 files changed

+13
-4
lines changed

5 files changed

+13
-4
lines changed

Diff for: .changeset/red-cheetahs-argue.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hono/oauth-providers': minor
3+
---
4+
5+
Add availbility to pass parameter state into OAuth middlewares

Diff for: packages/oauth-providers/src/providers/facebook/facebookAuth.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ export function facebookAuth(options: {
1212
fields: Fields[]
1313
client_id?: string
1414
client_secret?: string
15+
state?: string
1516
redirect_uri?: string
1617
}): MiddlewareHandler {
1718
return async (c, next) => {
18-
const newState = getRandomState()
19+
const newState = options.state || getRandomState()
1920
// Create new Auth instance
2021
const auth = new AuthFlow({
2122
client_id: options.client_id || (env(c).FACEBOOK_ID as string),

Diff for: packages/oauth-providers/src/providers/github/githubAuth.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ export function githubAuth(options: {
1212
client_secret?: string
1313
scope?: GitHubScope[]
1414
oauthApp?: boolean
15+
state?: string
1516
redirect_uri?: string
1617
}): MiddlewareHandler {
1718
return async (c, next) => {
18-
const newState = getRandomState()
19+
const newState = options.state || getRandomState()
1920
// Create new Auth instance
2021
const auth = new AuthFlow({
2122
client_id: options.client_id || (env(c).GITHUB_ID as string),

Diff for: packages/oauth-providers/src/providers/linkedin/linkedinAuth.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ export function linkedinAuth(options: {
1212
client_secret?: string
1313
scope?: LinkedInScope[]
1414
appAuth?: boolean
15+
state?: string
1516
redirect_uri?: string
1617
}): MiddlewareHandler {
1718
return async (c, next) => {
18-
const newState = getRandomState()
19+
const newState = options.state || getRandomState()
1920
// Create new Auth instance
2021
const auth = new AuthFlow({
2122
client_id: options.client_id || (env(c).LINKEDIN_ID as string),

Diff for: packages/oauth-providers/src/providers/x/xAuth.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ export function xAuth(options: {
1313
fields?: XFields[]
1414
client_id?: string
1515
client_secret?: string
16+
state?: string
1617
redirect_uri?: string
1718
}): MiddlewareHandler {
1819
return async (c, next) => {
1920
// Generate encoded "keys"
20-
const newState = getRandomState()
21+
const newState = options.state || getRandomState()
2122
const challenge = await getCodeChallenge()
2223

2324
const auth = new AuthFlow({

0 commit comments

Comments
 (0)