Skip to content

Commit

Permalink
feat: issue #45, created a method to sanitize the bearerPrefix.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriciovigolo committed Apr 17, 2018
1 parent 787e335 commit 6a3be53
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/services/keycloak.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ export class KeycloakService {
private bearerExcludedUrls: string[];
private bearerPrefix: string;

/**
* Sanitizes the bearer prefix, preparing it to be appended to
* the token.
*
* @param bearerPrefix - prefix to be appended to the authorization header as
* Authorization: <bearer-prefix> <token>.
*/
private sanitizeBearerPrefix(bearerPrefix: string | undefined): string {
let prefix: string = (bearerPrefix || 'bearer').trim();
return prefix.concat(' ');
}

/**
* Keycloak initialization. It should be called to initialize the adapter.
* Options is a object with 2 main parameters: config and initOptions. The first one
Expand Down Expand Up @@ -71,7 +83,7 @@ export class KeycloakService {
init(options: KeycloakOptions = {}): Promise<boolean> {
return new Promise((resolve, reject) => {
this.bearerExcludedUrls = options.bearerExcludedUrls || [];
this.bearerPrefix = options.bearerPrefix || 'bearer';
this.bearerPrefix = this.sanitizeBearerPrefix(options.bearerPrefix);
this.instance = Keycloak(options.config);
this.instance
.init(options.initOptions!)
Expand Down

0 comments on commit 6a3be53

Please sign in to comment.