Skip to content

Commit

Permalink
fix(authentication-oauth): Allow POST oauth callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Jun 4, 2024
1 parent c7b0111 commit ebf3de1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
9 changes: 8 additions & 1 deletion packages/authentication-oauth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createDebug } from '@feathersjs/commons'
import { resolveDispatch } from '@feathersjs/schema'

import { OAuthStrategy, OAuthProfile } from './strategy'
import { redirectHook, OAuthService } from './service'
import { redirectHook, OAuthService, OAuthCallbackService } from './service'
import { getGrantConfig, authenticationServiceOptions, OauthSetupSettings } from './utils'

const debug = createDebug('@feathersjs/authentication-oauth')
Expand Down Expand Up @@ -34,6 +34,7 @@ export const oauth =
const grantConfig = getGrantConfig(authService)
const serviceOptions = authenticationServiceOptions(authService, oauthOptions)
const servicePath = `${grantConfig.defaults.prefix || 'oauth'}/:provider`
const callbackServicePath = `${servicePath}/callback`

app.use(servicePath, new OAuthService(authService, oauthOptions), serviceOptions)

Expand All @@ -43,6 +44,12 @@ export const oauth =
around: { all: [resolveDispatch(), redirectHook()] }
})

app.use(
callbackServicePath,
new OAuthCallbackService(app.service(servicePath) as unknown as OAuthService),
serviceOptions
)

if (typeof oauthService.publish === 'function') {
app.service(servicePath).publish(() => null)
}
Expand Down
20 changes: 16 additions & 4 deletions packages/authentication-oauth/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,26 @@ export class OAuthService {
async get(override: string, params: OAuthParams) {
const result = await this.handler('GET', params, {}, override)

if (override === 'callback') {
return this.authenticate(params, result)
}

return result
}

async create(data: any, params: OAuthParams) {
return this.handler('POST', params, data)
}
}

export class OAuthCallbackService {
constructor(public service: OAuthService) {}

async find(params: OAuthParams) {
const result = await this.service.handler('GET', params, {}, 'callback')

return this.service.authenticate(params, result)
}

async create(data: any, params: OAuthParams) {
const result = await this.service.handler('POST', params, data, 'callback')

return this.service.authenticate(params, result)
}
}

0 comments on commit ebf3de1

Please sign in to comment.