Skip to content

Commit 589db36

Browse files
committed
fix: review comments
1 parent 0f3badb commit 589db36

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

extensions/authentication-passport/src/__tests__/acceptance/authentication-with-passport-strategy-oauth2-adapter.acceptance.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ import {
2424
expect,
2525
supertest,
2626
} from '@loopback/testlab';
27-
import {
28-
RestApplication,
29-
RestBindings,
30-
Response,
31-
} from '@loopback/rest';
27+
import {RestApplication, RestBindings, Response} from '@loopback/rest';
3228
import {
3329
startApp as startMockOauth2Server,
3430
stopApp as stopMockOauth2Server,
@@ -177,8 +173,8 @@ export class Oauth2Controller {
177173
// we have modeled this as a GET endpoint
178174
@get('/auth/thirdparty')
179175
// loginToThirdParty() is the handler for '/auth/thirdparty'
180-
// this method is injected with 'x-loopback-authentication-redirect-url'
181-
// the value for 'x-loopback-authentication-redirect-url' is set by the passport strategy adapter
176+
// this method is injected with redirect url and status
177+
// the value for 'authentication.redirect.url' is set by the authentication action provider
182178
loginToThirdParty(
183179
@inject('authentication.redirect.url')
184180
redirectUrl: string,
@@ -187,6 +183,8 @@ export class Oauth2Controller {
187183
@inject(RestBindings.Http.RESPONSE)
188184
response: Response,
189185
) {
186+
// controller handles redirect
187+
// and returns response object to indicate response is already handled
190188
response.statusCode = status || 302;
191189
response.setHeader('Location', redirectUrl);
192190
response.end();

packages/authentication/src/keys.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,16 @@ export namespace AuthenticationBindings {
118118

119119
// Make `CURRENT_USER` the alias of SecurityBindings.USER for backward compatibility
120120
export const CURRENT_USER = SecurityBindings.USER;
121+
122+
// Redirect url for authenticating current user
123+
export const AUTHENTICATION_REDIRECT_URL = BindingKey.create<string>(
124+
'authentication.redirect.url',
125+
);
126+
127+
// Authentication redirect status, usually 302 or 303, indicates a web client will redirect
128+
export const AUTHENTICATION_REDIRECT_STATUS = BindingKey.create<number>(
129+
'authentication.redirect.status',
130+
);
121131
}
122132

123133
/**

packages/authentication/src/providers/auth-action.provider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ export class AuthenticateActionProvider implements Provider<AuthenticateFn> {
5959
// bind redirection url and status as 'authentication.oauth2.redirectUrl' to context
6060
// controller should handle actual redirection
6161
this.ctx
62-
.bind('authentication.redirect.url')
62+
.bind(AuthenticationBindings.AUTHENTICATION_REDIRECT_URL)
6363
.to(redirectOptions.targetLocation);
6464
this.ctx
65-
.bind('authentication.redirect.status')
65+
.bind(AuthenticationBindings.AUTHENTICATION_REDIRECT_STATUS)
6666
.to(redirectOptions.statusCode);
6767
} else if (authResponse) {
6868
// if `strategy.authenticate()` returns an object of type UserProfile, set it as current user

packages/rest/src/router/redirect-route.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
import {OperationObject, SchemasObject} from '@loopback/openapi-v3';
77
import {ResolvedRoute, RouteEntry} from '.';
88
import {RequestContext} from '../request-context';
9-
import {
10-
OperationArgs,
11-
OperationRetval,
12-
PathParameterValues,
13-
} from '../types';
9+
import {OperationArgs, OperationRetval, PathParameterValues} from '../types';
1410

1511
export class RedirectRoute implements RouteEntry, ResolvedRoute {
1612
// ResolvedRoute API

0 commit comments

Comments
 (0)