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

Feature/angular 10 support #666

Merged
merged 4 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Remove URL dependency
  • Loading branch information
Sambego committed Jun 29, 2020
commit 882191f604a9eb1be9d7d0463b3b462b8a2f0541
7 changes: 5 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"@angular/common": "~9.1.1",
"@angular/compiler": "~9.1.1",
"@angular/core": "~9.1.1",
"url": "^0.11.0",
"@angular/platform-browser": "~9.1.1",
"@angular/platform-browser-dynamic": "~9.1.1",
"core-js": "^3.2.1",
Expand Down
16 changes: 5 additions & 11 deletions projects/angular-jwt/ng-package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/angular-jwt",
"lib": {
"entryFile": "src/index.ts",
"umdModuleIds": {
"url": "url"
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/angular-jwt",
"lib": {
"entryFile": "src/index.ts"
}
},
"whitelistedNonPeerDependencies": [
"url"
]
}
}
3 changes: 0 additions & 3 deletions projects/angular-jwt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,5 @@
"homepage": "https://github.com/auth0/angular2-jwt",
"peerDependencies": {
"@angular/common": ">=7.1.0"
},
"dependencies": {
"url": "^0.11.0"
}
}
31 changes: 17 additions & 14 deletions projects/angular-jwt/src/lib/jwt.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { JwtHelperService } from "./jwthelper.service";
import { JWT_OPTIONS } from "./jwtoptions.token";

import { mergeMap } from "rxjs/operators";
import { parse } from "url";
import { from, Observable } from "rxjs";

@Injectable()
Expand Down Expand Up @@ -42,18 +41,22 @@ export class JwtInterceptor implements HttpInterceptor {
}

isWhitelistedDomain(request: HttpRequest<any>): boolean {
const requestUrl: any = parse(request.url, false, true);
const hostName =
requestUrl.hostname !== null
? `${requestUrl.hostname}${
requestUrl.port && !this.standardPorts.includes(requestUrl.port)
? ":" + requestUrl.port
: ""
}`
: requestUrl.hostname;
const requestUrl: URL = new URL(request.url, window.location.origin);

// If the host equals the current window origin,
// the domain is whitelisted by default
if (requestUrl.host === window.location.host) {
return true;
}

// If not the current domain, check the whitelist
const hostName = `${requestUrl.hostname}${
requestUrl.port && !this.standardPorts.includes(requestUrl.port)
? ":" + requestUrl.port
: ""
}`;

return (
hostName === null ||
this.whitelistedDomains.findIndex((domain) =>
typeof domain === "string"
? domain === hostName
Expand All @@ -65,15 +68,15 @@ export class JwtInterceptor implements HttpInterceptor {
}

isBlacklistedRoute(request: HttpRequest<any>): boolean {
const requestedUrl = parse(request.url, false, true);
const requestedUrl: URL = new URL(request.url, window.location.origin);

return (
this.blacklistedRoutes.findIndex((route: string | RegExp) => {
if (typeof route === "string") {
const parsedRoute = parse(route, false, true);
const parsedRoute: URL = new URL(route, window.location.origin);
return (
parsedRoute.hostname === requestedUrl.hostname &&
parsedRoute.path === requestedUrl.path
parsedRoute.pathname === requestedUrl.pathname
);
}

Expand Down