Skip to content

feat(oauth-providers): availbility to pass state into oauth middlewares #917

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/red-cheetahs-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hono/oauth-providers': minor
---

Add availbility to pass parameter state into OAuth middlewares
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ export function facebookAuth(options: {
fields: Fields[]
client_id?: string
client_secret?: string
state?: string
redirect_uri?: string
}): MiddlewareHandler {
return async (c, next) => {
const newState = getRandomState()
const newState = options.state || getRandomState()
// Create new Auth instance
const auth = new AuthFlow({
client_id: options.client_id || (env(c).FACEBOOK_ID as string),
Expand Down
3 changes: 2 additions & 1 deletion packages/oauth-providers/src/providers/github/githubAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ export function githubAuth(options: {
client_secret?: string
scope?: GitHubScope[]
oauthApp?: boolean
state?: string
redirect_uri?: string
}): MiddlewareHandler {
return async (c, next) => {
const newState = getRandomState()
const newState = options.state || getRandomState()
// Create new Auth instance
const auth = new AuthFlow({
client_id: options.client_id || (env(c).GITHUB_ID as string),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ export function linkedinAuth(options: {
client_secret?: string
scope?: LinkedInScope[]
appAuth?: boolean
state?: string
redirect_uri?: string
}): MiddlewareHandler {
return async (c, next) => {
const newState = getRandomState()
const newState = options.state || getRandomState()
// Create new Auth instance
const auth = new AuthFlow({
client_id: options.client_id || (env(c).LINKEDIN_ID as string),
Expand Down
3 changes: 2 additions & 1 deletion packages/oauth-providers/src/providers/x/xAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ export function xAuth(options: {
fields?: XFields[]
client_id?: string
client_secret?: string
state?: string
redirect_uri?: string
}): MiddlewareHandler {
return async (c, next) => {
// Generate encoded "keys"
const newState = getRandomState()
const newState = options.state || getRandomState()
const challenge = await getCodeChallenge()

const auth = new AuthFlow({
Expand Down
Loading