Skip to content

Commit f962d29

Browse files
Pass optional state as parameter, so we can link other state info to it
1 parent fa8ed28 commit f962d29

File tree

6 files changed

+15
-5
lines changed

6 files changed

+15
-5
lines changed

.changeset/eighty-pandas-talk.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hono/oauth-providers': minor
3+
---
4+
5+
Optionally pass state as an option to oauth provider

packages/oauth-providers/src/providers/discord/discordAuth.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ export function discordAuth(options: {
1212
client_id?: string
1313
client_secret?: string
1414
redirect_uri?: string
15+
state?: string
1516
}): MiddlewareHandler {
1617
return async (c, next) => {
1718
// Generate encoded "keys"
18-
const newState = getRandomState()
19+
const newState = options.state || getRandomState()
1920

2021
// Create new Auth instance
2122
const auth = new AuthFlow({

packages/oauth-providers/src/providers/facebook/facebookAuth.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ export function facebookAuth(options: {
1313
client_id?: string
1414
client_secret?: string
1515
redirect_uri?: string
16+
state?: 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),

packages/oauth-providers/src/providers/github/githubAuth.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ export function githubAuth(options: {
1313
scope?: GitHubScope[]
1414
oauthApp?: boolean
1515
redirect_uri?: string
16+
state?: 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),

packages/oauth-providers/src/providers/linkedin/linkedinAuth.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ export function linkedinAuth(options: {
1313
scope?: LinkedInScope[]
1414
appAuth?: boolean
1515
redirect_uri?: string
16+
state?: 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),

packages/oauth-providers/src/providers/x/xAuth.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ export function xAuth(options: {
1414
client_id?: string
1515
client_secret?: string
1616
redirect_uri?: string
17+
state?: 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)