Skip to content

Commit

Permalink
fix(oauth-providers): oauth-middleware: load env.SECRETS with hono/…
Browse files Browse the repository at this point in the history
…adapter (#588)

* load env with hono/adapter

* add changeset

* update changeset type
  • Loading branch information
jokester authored Jun 24, 2024
1 parent 352e74f commit 69eca66
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-frogs-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hono/oauth-providers': patch
---

load env.SECRET with hono/adapter, to support non-worker
5 changes: 3 additions & 2 deletions packages/oauth-providers/src/providers/discord/discordAuth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { MiddlewareHandler } from 'hono'
import { setCookie, getCookie } from 'hono/cookie'
import { env } from 'hono/adapter'
import { HTTPException } from 'hono/http-exception'

import { getRandomState } from '../../utils/getRandomState'
Expand All @@ -17,8 +18,8 @@ export function discordAuth(options: {

// Create new Auth instance
const auth = new AuthFlow({
client_id: options.client_id || (c.env?.DISCORD_ID as string),
client_secret: options.client_secret || (c.env?.DISCORD_SECRET as string),
client_id: options.client_id || (env(c).DISCORD_ID as string),
client_secret: options.client_secret || (env(c).DISCORD_SECRET as string),
redirect_uri: c.req.url.split('?')[0],
scope: options.scope,
state: newState,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { MiddlewareHandler } from 'hono'
import { setCookie, getCookie } from 'hono/cookie'
import { env } from 'hono/adapter'
import { HTTPException } from 'hono/http-exception'

import { getRandomState } from '../../utils/getRandomState'
Expand All @@ -16,8 +17,8 @@ export function facebookAuth(options: {
const newState = getRandomState()
// Create new Auth instance
const auth = new AuthFlow({
client_id: options.client_id || (c.env?.FACEBOOK_ID as string),
client_secret: options.client_secret || (c.env?.FACEBOOK_SECRET as string),
client_id: options.client_id || (env(c).FACEBOOK_ID as string),
client_secret: options.client_secret || (env(c).FACEBOOK_SECRET as string),
redirect_uri: c.req.url.split('?')[0],
scope: options.scope,
fields: options.fields,
Expand Down
5 changes: 3 additions & 2 deletions packages/oauth-providers/src/providers/github/githubAuth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { MiddlewareHandler } from 'hono'
import { getCookie, setCookie } from 'hono/cookie'
import { env } from 'hono/adapter'
import { HTTPException } from 'hono/http-exception'

import { getRandomState } from '../../utils/getRandomState'
Expand All @@ -16,8 +17,8 @@ export function githubAuth(options: {
const newState = getRandomState()
// Create new Auth instance
const auth = new AuthFlow({
client_id: options.client_id || (c.env?.GITHUB_ID as string),
client_secret: options.client_secret || (c.env?.GITHUB_SECRET as string),
client_id: options.client_id || (env(c).GITHUB_ID as string),
client_secret: options.client_secret || (env(c).GITHUB_SECRET as string),
scope: options.scope,
state: newState,
oauthApp: options.oauthApp || false,
Expand Down
5 changes: 3 additions & 2 deletions packages/oauth-providers/src/providers/google/googleAuth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { MiddlewareHandler } from 'hono'
import { getCookie, setCookie } from 'hono/cookie'
import { env } from 'hono/adapter'
import { HTTPException } from 'hono/http-exception'

import { getRandomState } from '../../utils/getRandomState'
Expand All @@ -17,8 +18,8 @@ export function googleAuth(options: {
const newState = options.state || getRandomState()
// Create new Auth instance
const auth = new AuthFlow({
client_id: options.client_id || (c.env?.GOOGLE_ID as string),
client_secret: options.client_secret || (c.env?.GOOGLE_SECRET as string),
client_id: options.client_id || (env(c).GOOGLE_ID as string),
client_secret: options.client_secret || (env(c).GOOGLE_SECRET as string),
redirect_uri: c.req.url.split('?')[0],
login_hint: options.login_hint,
prompt: options.prompt,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { MiddlewareHandler } from 'hono'
import { getCookie, setCookie } from 'hono/cookie'
import { env } from 'hono/adapter'
import { HTTPException } from 'hono/http-exception'

import { getRandomState } from '../../utils/getRandomState'
Expand All @@ -16,8 +17,8 @@ export function linkedinAuth(options: {
const newState = getRandomState()
// Create new Auth instance
const auth = new AuthFlow({
client_id: options.client_id || (c.env?.LINKEDIN_ID as string),
client_secret: options.client_secret || (c.env?.LINKEDIN_SECRET as string),
client_id: options.client_id || (env(c).LINKEDIN_ID as string),
client_secret: options.client_secret || (env(c).LINKEDIN_SECRET as string),
redirect_uri: c.req.url.split('?')[0],
scope: options.scope,
state: newState,
Expand Down
5 changes: 3 additions & 2 deletions packages/oauth-providers/src/providers/x/xAuth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { MiddlewareHandler } from 'hono'
import { getCookie, setCookie } from 'hono/cookie'
import { env } from 'hono/adapter'
import { HTTPException } from 'hono/http-exception'

import { getCodeChallenge } from '../../utils/getCodeChallenge'
Expand All @@ -19,8 +20,8 @@ export function xAuth(options: {
const challenge = await getCodeChallenge()

const auth = new AuthFlow({
client_id: options.client_id || (c.env?.X_ID as string),
client_secret: options.client_secret || (c.env?.X_SECRET as string),
client_id: options.client_id || (env(c).X_ID as string),
client_secret: options.client_secret || (env(c).X_SECRET as string),
redirect_uri: c.req.url.split('?')[0],
scope: options.scope,
fields: options.fields,
Expand Down

0 comments on commit 69eca66

Please sign in to comment.