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

use custom encoder to allow + in password #272

Merged
merged 2 commits into from
May 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 @@ -10,6 +10,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 @@ -554,7 +555,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