Wealthbox Provider #11535
Unanswered
aakash19here
asked this question in
Help
Wealthbox Provider
#11535
Replies: 1 comment
-
import { OAuthConfig, OAuthUserConfig } from 'next-auth/providers'
export interface WealthboxProfile {
id: string
name: string
email: string
}
export default function WealthboxProvider<P extends WealthboxProfile>(
config?: OAuthUserConfig<P>
): OAuthConfig<P> {
return {
id: 'wealthbox',
name: 'Wealthbox',
type: 'oauth',
authorization: {
url: 'https://app.crmworkspace.com/oauth/authorize',
params: {
response_type: 'code',
client_id: process.env.WEALTHBOX_CLIENT_ID as string,
redirect_uri: process.env.WEALTHBOX_CALLBACK_URL as string,
scope: 'login data'
}
},
token: {
url: 'https://app.crmworkspace.com/oauth/token',
async request(context) {
const response = await fetch(
'https://app.crmworkspace.com/oauth/token',
{
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams({
client_id: context.provider.clientId as string,
client_secret: context.provider.clientSecret as string,
code: context.params.code ?? '',
grant_type: 'authorization_code',
redirect_uri: process.env.WEALTHBOX_CALLBACK_URL as string
})
}
)
console.log('Token response received with status:', response.status)
const tokens = await response.json()
const { created_at, ...filteredTokens } = tokens
filteredTokens.expires_at =
typeof filteredTokens.expires_at === 'string'
? parseInt(filteredTokens.expires_at, 10)
: filteredTokens.expires_at
return {
tokens: filteredTokens
}
}
},
userinfo: {
url: 'https://api.crmworkspace.com/v1/me',
async request(context) {
const { tokens } = context
if (!tokens || !tokens.access_token) {
console.error(
'No access token available for userinfo request:',
JSON.stringify(tokens)
)
throw new Error('No access token available')
}
const response = await fetch('https://api.crmworkspace.com/v1/me', {
headers: {
Authorization: `Bearer ${tokens.access_token}`
}
})
if (!response.ok) {
console.error(
'Failed to fetch user information, response status:',
response.status
)
throw new Error('Failed to fetch user information')
}
return await response.json()
}
},
profile(profile) {
return {
id: profile.id,
name: profile.name,
email: profile.email
}
},
clientId: process.env.WEALTHBOX_CLIENT_ID,
clientSecret: process.env.WEALTHBOX_CLIENT_SECRET
}
}
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm working with Nextjs and next-auth , app is deployed on AWS using SST.
The issue is I want to implement Wealth box OAuth , docs and the callback url for the app is not registered for localhost (my client says its not possible).
How am I supposed to implement it cause I would need to test things locally before pushing anything. Also refresh token is to be implemented.
Beta Was this translation helpful? Give feedback.
All reactions