Skip to content

Commit

Permalink
fix: make OAuth 1 work after refactoring (#1218)
Browse files Browse the repository at this point in the history
* chore: add twitter provider to dev app

* feat: bind client instance to overriden methods

* fix: don't add extra params to getOAuthRequestToken

* chore: add twitter to env example, add secret gen instructions
  • Loading branch information
balazsorban44 committed Feb 1, 2021
1 parent d67f1b7 commit f2a7ee0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
13 changes: 11 additions & 2 deletions .env.local.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Rename file to .env.local and populate values
# to be able to run the dev app

NEXTAUTH_URL=http://localhost:3000
SECRET=
SECRET= Linux: `openssl rand -hex 32` or https://generate-secret.now.sh/32

AUTH0_ID=
AUTH0_DOMAIN=
AUTH0_SECRET=

GITHUB_ID=
GITHUB_SECRET=
GITHUB_SECRET=

TWITTER_ID=
TWITTER_SECRET=
6 changes: 5 additions & 1 deletion pages/api/auth/[...nextauth].js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export default NextAuth({
clientSecret: process.env.AUTH0_SECRET,
domain: process.env.AUTH0_DOMAIN,
protection: "pkce"
})
}),
Providers.Twitter({
clientId: process.env.TWITTER_ID,
clientSecret: process.env.TWITTER_SECRET,
}),
],
// Database optional. MySQL, Maria DB, Postgres and MongoDB are supported.
// https://next-auth.js.org/configuration/databases
Expand Down
6 changes: 3 additions & 3 deletions src/server/lib/oauth/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function oAuthClient (provider) {
)

// Promisify get() and getOAuth2AccessToken() for OAuth1
const originalGet = oauth1Client.get
const originalGet = oauth1Client.get.bind(oauth1Client)
oauth1Client.get = (...args) => {
return new Promise((resolve, reject) => {
originalGet(...args, (error, result) => {
Expand All @@ -50,7 +50,7 @@ export default function oAuthClient (provider) {
})
})
}
const originalGetOAuth1AccessToken = oauth1Client.getOAuthAccessToken
const originalGetOAuth1AccessToken = oauth1Client.getOAuthAccessToken.bind(oauth1Client)
oauth1Client.getOAuthAccessToken = (...args) => {
return new Promise((resolve, reject) => {
originalGetOAuth1AccessToken(...args, (error, accessToken, refreshToken, results) => {
Expand All @@ -62,7 +62,7 @@ export default function oAuthClient (provider) {
})
}

const originalGetOAuthRequestToken = oauth1Client.getOAuthRequestToken
const originalGetOAuthRequestToken = oauth1Client.getOAuthRequestToken.bind(oauth1Client)
oauth1Client.getOAuthRequestToken = (...args) => {
return new Promise((resolve, reject) => {
originalGetOAuthRequestToken(...args, (error, oauthToken) => {
Expand Down
2 changes: 1 addition & 1 deletion src/server/lib/signin/oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default async function getAuthorizationUrl (req) {
}

try {
const oAuthToken = await client.getOAuthRequestToken(provider.callbackUrl)
const oAuthToken = await client.getOAuthRequestToken()
const url = `${provider.authorizationUrl}?oauth_token=${oAuthToken}`
logger.debug('GET_AUTHORIZATION_URL', url)
return url
Expand Down

0 comments on commit f2a7ee0

Please sign in to comment.