feat(oauth-providers): Allow passing state in google oath middleware (#454)

* improve(#453): Allow for state to be passed to AuthFlow

* fix(#453): No need to cast as string

* chore(#453): Create changeset

Closes #453

* fix(#453): Needed to take CSRF into account
pull/469/head
Aaron Ware 2024-04-21 19:08:03 -04:00 committed by GitHub
parent 3c351e1097
commit 65418948ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
'@hono/oauth-providers': minor
---
Allow for an optional state arg to be passed to Google Auth middleware

View File

@ -11,9 +11,10 @@ export function googleAuth(options: {
prompt?: 'none' | 'consent' | 'select_account'
client_id?: string
client_secret?: 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 || (c.env?.GOOGLE_ID as string),