Skip to content

Commit bc68d11

Browse files
authored
refactor(auth): require valid token by default (#2259)
BREAKING CHANGE: `requireValidToken` set to true by default. Now if response contains invalid token `NbAuthIllegalTokenError` is thrown. To enable old behavior, set `requireValidToken: false` in the auth strategy method config, e.g.: ``` NbPasswordAuthStrategy.setup({ // ... login: { // ... requireValidToken: false, }, }); ``` or ``` NbOAuth2AuthStrategy.setup({ // ... authorize: { // ... requireValidToken: false, }, }); ```
1 parent 8e52fc0 commit bc68d11

File tree

5 files changed

+12
-13
lines changed

5 files changed

+12
-13
lines changed

src/framework/auth/strategies/oauth2/oauth2-strategy.options.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export class NbOAuth2AuthStrategyOptions extends NbAuthStrategyOptions {
4747
} = {
4848
endpoint: 'authorize',
4949
responseType: NbOAuth2ResponseType.CODE,
50+
requireValidToken: true,
5051
};
5152
token?: {
5253
endpoint?: string;
@@ -58,7 +59,7 @@ export class NbOAuth2AuthStrategyOptions extends NbAuthStrategyOptions {
5859
} = {
5960
endpoint: 'token',
6061
grantType: NbOAuth2GrantType.AUTHORIZATION_CODE,
61-
requireValidToken: false,
62+
requireValidToken: true,
6263
class: NbAuthOAuth2Token,
6364
};
6465
refresh?: {
@@ -69,6 +70,7 @@ export class NbOAuth2AuthStrategyOptions extends NbAuthStrategyOptions {
6970
} = {
7071
endpoint: 'token',
7172
grantType: NbOAuth2GrantType.REFRESH_TOKEN,
73+
requireValidToken: true,
7274
};
7375
}
7476

src/framework/auth/strategies/oauth2/oauth2-strategy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import { NbAuthStrategyClass } from '../../auth.options';
5555
* endpoint?: string;
5656
* redirectUri?: string;
5757
* responseType?: string;
58-
* requireValidToken: false,
58+
* requireValidToken: true,
5959
* scope?: string;
6060
* state?: string;
6161
* params?: { [key: string]: string };
@@ -66,7 +66,7 @@ import { NbAuthStrategyClass } from '../../auth.options';
6666
* token?: {
6767
* endpoint?: string;
6868
* grantType?: string;
69-
* requireValidToken: false,
69+
* requireValidToken: true,
7070
* redirectUri?: string;
7171
* scope?: string;
7272
* class: NbAuthTokenClass,
@@ -79,7 +79,7 @@ import { NbAuthStrategyClass } from '../../auth.options';
7979
* endpoint?: string;
8080
* grantType?: string;
8181
* scope?: string;
82-
* requireValidToken: false,
82+
* requireValidToken: true,
8383
* } = {
8484
* endpoint: 'token',
8585
* grantType: NbOAuth2GrantType.REFRESH_TOKEN,

src/framework/auth/strategies/password/password-strategy-options.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class NbPasswordAuthStrategyOptions extends NbAuthStrategyOptions {
4343
alwaysFail: false,
4444
endpoint: 'login',
4545
method: 'post',
46-
requireValidToken: false,
46+
requireValidToken: true,
4747
redirect: {
4848
success: '/',
4949
failure: null,
@@ -55,7 +55,7 @@ export class NbPasswordAuthStrategyOptions extends NbAuthStrategyOptions {
5555
alwaysFail: false,
5656
endpoint: 'register',
5757
method: 'post',
58-
requireValidToken: false,
58+
requireValidToken: true,
5959
redirect: {
6060
success: '/',
6161
failure: null,
@@ -98,7 +98,7 @@ export class NbPasswordAuthStrategyOptions extends NbAuthStrategyOptions {
9898
refreshToken?: boolean | NbPasswordStrategyModule = {
9999
endpoint: 'refresh-token',
100100
method: 'post',
101-
requireValidToken: false,
101+
requireValidToken: true,
102102
redirect: {
103103
success: null,
104104
failure: null,

src/framework/auth/strategies/password/password-strategy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { NbAuthIllegalTokenError } from '../../services/token/token';
3131
* alwaysFail: false,
3232
* endpoint: 'login',
3333
* method: 'post',
34-
* requireValidToken: false,
34+
* requireValidToken: true,
3535
* redirect: {
3636
* success: '/',
3737
* failure: null,
@@ -43,7 +43,7 @@ import { NbAuthIllegalTokenError } from '../../services/token/token';
4343
* alwaysFail: false,
4444
* endpoint: 'register',
4545
* method: 'post',
46-
* requireValidToken: false,
46+
* requireValidToken: true,
4747
* redirect: {
4848
* success: '/',
4949
* failure: null,
@@ -86,7 +86,7 @@ import { NbAuthIllegalTokenError } from '../../services/token/token';
8686
* refreshToken?: boolean | NbPasswordStrategyModule = {
8787
* endpoint: 'refresh-token',
8888
* method: 'post',
89-
* requireValidToken: false,
89+
* requireValidToken: true,
9090
* redirect: {
9191
* success: null,
9292
* failure: null,

src/playground/without-layout/auth/auth.module.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ export function filterInterceptorRequest(req: HttpRequest<any>) {
8989
token: {
9090
class: NbAuthJWTToken,
9191
},
92-
login: {
93-
requireValidToken: false,
94-
},
9592
baseEndpoint: 'http://localhost:4400/api/auth/',
9693
logout: {
9794
redirect: {

0 commit comments

Comments
 (0)