Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the Apple POST callback issue while authenticating #3510

Draft
wants to merge 2 commits into
base: dove
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions 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,16 +34,23 @@ export const oauth =
const grantConfig = getGrantConfig(authService)
const serviceOptions = authenticationServiceOptions(authService, oauthOptions)
const servicePath = `${grantConfig.defaults.prefix || 'oauth'}/:provider`
const callbackServicePath = `${servicePath}/callback`
const oauthService = new OAuthService(authService, oauthOptions)

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

const oauthService = app.service(servicePath)

oauthService.hooks({
app.use(servicePath, oauthService, serviceOptions)
app.use(callbackServicePath, new OAuthCallbackService(oauthService), serviceOptions)
app.service(servicePath).hooks({
around: { all: [resolveDispatch(), redirectHook()] }
})
app.service(callbackServicePath).hooks({
around: { all: [resolveDispatch(), redirectHook()] }
})

if (typeof oauthService.publish === 'function') {
if (typeof app.service(servicePath) === 'function') {
app.service(servicePath).publish(() => null)
}

if (typeof app.service(callbackServicePath).publish === 'function') {
app.service(callbackServicePath).publish(() => null)
}
}
19 changes: 16 additions & 3 deletions packages/authentication-oauth/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,6 @@ 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
}
Expand All @@ -177,3 +174,19 @@ export class OAuthService {
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)
}
}
2 changes: 1 addition & 1 deletion packages/authentication-oauth/test/utils/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,4 @@ const on = {
authorize: (_opts: any) => {},
access: (_opts: any) => {},
profile: (_opts: any) => {}
}
}
8 changes: 4 additions & 4 deletions packages/transport-commons/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ export function getStatusCode(context: HookContext, body: any, location: string
return http.status
}

if (context.method === 'create') {
return statusCodes.created
}

if (location !== undefined) {
return statusCodes.seeOther
}
Expand All @@ -74,6 +70,10 @@ export function getStatusCode(context: HookContext, body: any, location: string
return statusCodes.noContent
}

if (context.method === 'create') {
return statusCodes.created
}

return statusCodes.success
}

Expand Down