Skip to content

Commit

Permalink
Merge pull request #272 from marvinosswald/master
Browse files Browse the repository at this point in the history
use custom encoder to allow + in password
  • Loading branch information
manfredsteyer authored May 9, 2018
2 parents 3da1a94 + eed45b8 commit d10c441
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
21 changes: 21 additions & 0 deletions angular-oauth2-oidc/src/encoder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {HttpParameterCodec} from '@angular/common/http';
/**
* This custom encoder allows charactes like +, % and / to be used in passwords
*/
export class WebHttpUrlEncodingCodec implements HttpParameterCodec {
encodeKey(k: string): string {
return encodeURIComponent(k);
}

encodeValue(v: string): string {
return encodeURIComponent(v);
}

decodeKey(k: string): string {
return decodeURIComponent(k);
}

decodeValue(v: string) {
return decodeURIComponent(v);
}
}
9 changes: 8 additions & 1 deletion angular-oauth2-oidc/src/oauth-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { OAuthEvent, OAuthInfoEvent, OAuthErrorEvent, OAuthSuccessEvent } from '
import { OAuthStorage, LoginOptions, ParsedIdToken, OidcDiscoveryDoc, TokenResponse, UserInfo } from './types';
import { b64DecodeUnicode } from './base64-helper';
import { AuthConfig } from './auth.config';
import { WebHttpUrlEncodingCodec } from './encoder';

/**
* Service for logging in and logging out with
Expand Down Expand Up @@ -550,7 +551,13 @@ export class OAuthService
}

return new Promise((resolve, reject) => {
let params = new HttpParams()
/**
* A `HttpParameterCodec` that uses `encodeURIComponent` and `decodeURIComponent` to
* serialize and parse URL parameter keys and values.
*
* @stable
*/
let params = new HttpParams({encoder: new WebHttpUrlEncodingCodec() })
.set('grant_type', 'password')
.set('client_id', this.clientId)
.set('scope', this.scope)
Expand Down

0 comments on commit d10c441

Please sign in to comment.