Pass optional state as parameter, so we can link other state info to it

pull/976/head
mani 2025-02-24 01:01:35 +02:00
parent fa8ed2804f
commit f962d29eda
6 changed files with 15 additions and 5 deletions

View File

@ -0,0 +1,5 @@
---
'@hono/oauth-providers': minor
---
Optionally pass state as an option to oauth provider

View File

@ -12,10 +12,11 @@ export function discordAuth(options: {
client_id?: string
client_secret?: string
redirect_uri?: string
state?: string
}): MiddlewareHandler {
return async (c, next) => {
// Generate encoded "keys"
const newState = getRandomState()
const newState = options.state || getRandomState()
// Create new Auth instance
const auth = new AuthFlow({

View File

@ -13,9 +13,10 @@ export function facebookAuth(options: {
client_id?: string
client_secret?: string
redirect_uri?: string
state?: 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),

View File

@ -13,9 +13,10 @@ export function githubAuth(options: {
scope?: GitHubScope[]
oauthApp?: boolean
redirect_uri?: string
state?: 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),

View File

@ -13,9 +13,10 @@ export function linkedinAuth(options: {
scope?: LinkedInScope[]
appAuth?: boolean
redirect_uri?: string
state?: 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),

View File

@ -14,10 +14,11 @@ export function xAuth(options: {
client_id?: string
client_secret?: string
redirect_uri?: string
state?: 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({