Skip to content

Commit

Permalink
refactor(auth): require valid token by default (#2259)
Browse files Browse the repository at this point in the history
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,
  },
});
```
  • Loading branch information
yggg authored Mar 6, 2020
1 parent 8e52fc0 commit bc68d11
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class NbOAuth2AuthStrategyOptions extends NbAuthStrategyOptions {
} = {
endpoint: 'authorize',
responseType: NbOAuth2ResponseType.CODE,
requireValidToken: true,
};
token?: {
endpoint?: string;
Expand All @@ -58,7 +59,7 @@ export class NbOAuth2AuthStrategyOptions extends NbAuthStrategyOptions {
} = {
endpoint: 'token',
grantType: NbOAuth2GrantType.AUTHORIZATION_CODE,
requireValidToken: false,
requireValidToken: true,
class: NbAuthOAuth2Token,
};
refresh?: {
Expand All @@ -69,6 +70,7 @@ export class NbOAuth2AuthStrategyOptions extends NbAuthStrategyOptions {
} = {
endpoint: 'token',
grantType: NbOAuth2GrantType.REFRESH_TOKEN,
requireValidToken: true,
};
}

Expand Down
6 changes: 3 additions & 3 deletions src/framework/auth/strategies/oauth2/oauth2-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import { NbAuthStrategyClass } from '../../auth.options';
* endpoint?: string;
* redirectUri?: string;
* responseType?: string;
* requireValidToken: false,
* requireValidToken: true,
* scope?: string;
* state?: string;
* params?: { [key: string]: string };
Expand All @@ -66,7 +66,7 @@ import { NbAuthStrategyClass } from '../../auth.options';
* token?: {
* endpoint?: string;
* grantType?: string;
* requireValidToken: false,
* requireValidToken: true,
* redirectUri?: string;
* scope?: string;
* class: NbAuthTokenClass,
Expand All @@ -79,7 +79,7 @@ import { NbAuthStrategyClass } from '../../auth.options';
* endpoint?: string;
* grantType?: string;
* scope?: string;
* requireValidToken: false,
* requireValidToken: true,
* } = {
* endpoint: 'token',
* grantType: NbOAuth2GrantType.REFRESH_TOKEN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class NbPasswordAuthStrategyOptions extends NbAuthStrategyOptions {
alwaysFail: false,
endpoint: 'login',
method: 'post',
requireValidToken: false,
requireValidToken: true,
redirect: {
success: '/',
failure: null,
Expand All @@ -55,7 +55,7 @@ export class NbPasswordAuthStrategyOptions extends NbAuthStrategyOptions {
alwaysFail: false,
endpoint: 'register',
method: 'post',
requireValidToken: false,
requireValidToken: true,
redirect: {
success: '/',
failure: null,
Expand Down Expand Up @@ -98,7 +98,7 @@ export class NbPasswordAuthStrategyOptions extends NbAuthStrategyOptions {
refreshToken?: boolean | NbPasswordStrategyModule = {
endpoint: 'refresh-token',
method: 'post',
requireValidToken: false,
requireValidToken: true,
redirect: {
success: null,
failure: null,
Expand Down
6 changes: 3 additions & 3 deletions src/framework/auth/strategies/password/password-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { NbAuthIllegalTokenError } from '../../services/token/token';
* alwaysFail: false,
* endpoint: 'login',
* method: 'post',
* requireValidToken: false,
* requireValidToken: true,
* redirect: {
* success: '/',
* failure: null,
Expand All @@ -43,7 +43,7 @@ import { NbAuthIllegalTokenError } from '../../services/token/token';
* alwaysFail: false,
* endpoint: 'register',
* method: 'post',
* requireValidToken: false,
* requireValidToken: true,
* redirect: {
* success: '/',
* failure: null,
Expand Down Expand Up @@ -86,7 +86,7 @@ import { NbAuthIllegalTokenError } from '../../services/token/token';
* refreshToken?: boolean | NbPasswordStrategyModule = {
* endpoint: 'refresh-token',
* method: 'post',
* requireValidToken: false,
* requireValidToken: true,
* redirect: {
* success: null,
* failure: null,
Expand Down
3 changes: 0 additions & 3 deletions src/playground/without-layout/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ export function filterInterceptorRequest(req: HttpRequest<any>) {
token: {
class: NbAuthJWTToken,
},
login: {
requireValidToken: false,
},
baseEndpoint: 'http://localhost:4400/api/auth/',
logout: {
redirect: {
Expand Down

0 comments on commit bc68d11

Please sign in to comment.