Skip to content

Commit

Permalink
fix: extends from RequestAccesTokenBody interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedrangel committed Sep 2, 2024
1 parent 3996b33 commit fcc1a2f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/runtime/server/lib/oauth/tiktok.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { eventHandler, getQuery, sendRedirect } from 'h3'
import { withQuery } from 'ufo'
import { defu } from 'defu'
import { sha256 } from 'ohash'
import { handleAccessTokenErrorResponse, handleMissingConfiguration, getOAuthRedirectURL, requestAccessToken } from '../utils'
import { handleAccessTokenErrorResponse, handleMissingConfiguration, getOAuthRedirectURL, requestAccessToken, type RequestAccessTokenBody } from '../utils'
import { useRuntimeConfig, createError } from '#imports'
import type { OAuthConfig } from '#auth-utils'

Expand Down Expand Up @@ -93,6 +93,11 @@ export function oauthTikTokEventHandler({ config, onSuccess, onError }: OAuthCon
)
}

interface TikTokRequestAccessTokenBody extends RequestAccessTokenBody {
client_key: string
code_verifier?: string
}

const tokens = await requestAccessToken(config.tokenURL as string, {
body: {
grant_type: 'authorization_code',
Expand All @@ -101,7 +106,7 @@ export function oauthTikTokEventHandler({ config, onSuccess, onError }: OAuthCon
client_secret: config.clientSecret,
code: query.code,
...config.sandbox ? { code_verifier: codeVerifier } : {},
},
} as TikTokRequestAccessTokenBody,
},
)

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/server/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function getOAuthRedirectURL(event: H3Event): string {
*
* @see https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.3
*/
interface RequestAccessTokenBody {
export interface RequestAccessTokenBody {
grant_type: 'authorization_code'
code: string
redirect_uri: string
Expand Down

0 comments on commit fcc1a2f

Please sign in to comment.