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

Changing any private accessors to protected to enable customization by implementing projects #535

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions projects/angular-token/src/lib/angular-token.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { tap } from 'rxjs/operators';
@Injectable()
export class AngularTokenInterceptor implements HttpInterceptor {

constructor( private tokenService: AngularTokenService ) { }
constructor( protected tokenService: AngularTokenService ) { }

intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {

Expand Down Expand Up @@ -43,7 +43,7 @@ export class AngularTokenInterceptor implements HttpInterceptor {


// Parse Auth data from response
private handleResponse(res: HttpResponse<any> | HttpErrorResponse | HttpEvent<any>): void {
protected handleResponse(res: HttpResponse<any> | HttpErrorResponse | HttpEvent<any>): void {
if (res instanceof HttpResponse || res instanceof HttpErrorResponse) {
if (this.tokenService.tokenOptions.apiBase === null || (res.url && res.url.match(this.tokenService.tokenOptions.apiBase))) {
this.tokenService.getAuthHeadersFromResponse(res);
Expand Down
40 changes: 20 additions & 20 deletions projects/angular-token/src/lib/angular-token.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,20 @@ export class AngularTokenService implements CanActivate {
this.options = (<any>Object).assign(this.options, options);
}

private options: AngularTokenOptions;
protected options: AngularTokenOptions;
public userType: BehaviorSubject<UserType> = new BehaviorSubject<UserType>(null);
public authData: BehaviorSubject<AuthData> = new BehaviorSubject<AuthData>(null);
public userData: BehaviorSubject<UserData> = new BehaviorSubject<UserData>(null);
private global: Window | any;
protected global: Window | any;

private localStorage: Storage | any = {};
protected localStorage: Storage | any = {};

constructor(
private http: HttpClient,
protected http: HttpClient,
@Inject(ANGULAR_TOKEN_OPTIONS) config: any,
@Inject(PLATFORM_ID) private platformId: Object,
@Optional() private activatedRoute: ActivatedRoute,
@Optional() private router: Router
@Inject(PLATFORM_ID) protected platformId: Object,
@Optional() protected activatedRoute: ActivatedRoute,
@Optional() protected router: Router
) {
this.global = (typeof window !== 'undefined') ? window : {};

Expand Down Expand Up @@ -424,11 +424,11 @@ export class AngularTokenService implements CanActivate {
*
*/

private getUserPath(): string {
protected getUserPath(): string {
return (this.userType.value == null) ? '' : this.userType.value.path + '/';
}

private getApiPath(): string {
protected getApiPath(): string {
let constructedPath = '';

if (this.options.apiBase != null) {
Expand All @@ -442,11 +442,11 @@ export class AngularTokenService implements CanActivate {
return constructedPath;
}

private getServerPath(): string {
protected getServerPath(): string {
return this.getApiPath() + this.getUserPath();
}

private getOAuthPath(oAuthType: string): string {
protected getOAuthPath(oAuthType: string): string {
let oAuthPath: string;

oAuthPath = this.options.oAuthPaths[oAuthType];
Expand All @@ -458,7 +458,7 @@ export class AngularTokenService implements CanActivate {
return oAuthPath;
}

private getOAuthUrl(oAuthPath: string, callbackUrl: string, windowType: string): string {
protected getOAuthUrl(oAuthPath: string, callbackUrl: string, windowType: string): string {
let url: string;

url = `${this.options.oAuthBase}/${oAuthPath}`;
Expand All @@ -480,7 +480,7 @@ export class AngularTokenService implements CanActivate {
*/

// Try to load auth data
private tryLoadAuthData(): void {
protected tryLoadAuthData(): void {

const userType = this.getUserTypeByName(this.localStorage.getItem('userType'));

Expand Down Expand Up @@ -515,7 +515,7 @@ export class AngularTokenService implements CanActivate {
}

// Parse Auth data from post message
private getAuthDataFromPostMessage(data: any): void {
protected getAuthDataFromPostMessage(data: any): void {
const authData: AuthData = {
accessToken: data['auth_token'],
client: data['client_id'],
Expand Down Expand Up @@ -544,7 +544,7 @@ export class AngularTokenService implements CanActivate {
}

// Try to get auth data from url parameters.
private getAuthDataFromParams(): void {
protected getAuthDataFromParams(): void {
this.activatedRoute.queryParams.subscribe(queryParams => {
const authData: AuthData = {
accessToken: queryParams['token'] || queryParams['auth_token'],
Expand All @@ -567,7 +567,7 @@ export class AngularTokenService implements CanActivate {
*/

// Write auth data to storage
private setAuthData(authData: AuthData): void {
protected setAuthData(authData: AuthData): void {
if (this.checkAuthData(authData)) {

this.authData.next(authData);
Expand All @@ -593,7 +593,7 @@ export class AngularTokenService implements CanActivate {
*/

// Check if auth data complete and if response token is newer
private checkAuthData(authData: AuthData): boolean {
protected checkAuthData(authData: AuthData): boolean {

if (
authData.accessToken != null &&
Expand All @@ -617,7 +617,7 @@ export class AngularTokenService implements CanActivate {
*
*/

private requestCredentialsViaPostMessage(authWindow: any): Observable<any> {
protected requestCredentialsViaPostMessage(authWindow: any): Observable<any> {
const pollerObserv = interval(500);

const responseObserv = fromEvent(this.global, 'message').pipe(
Expand All @@ -640,7 +640,7 @@ export class AngularTokenService implements CanActivate {
return responseObserv;
}

private oAuthWindowResponseFilter(data: any): any {
protected oAuthWindowResponseFilter(data: any): any {
if (data.message === 'deliverCredentials' || data.message === 'authFailure') {
return data;
}
Expand All @@ -654,7 +654,7 @@ export class AngularTokenService implements CanActivate {
*/

// Match user config by user config name
private getUserTypeByName(name: string): UserType {
protected getUserTypeByName(name: string): UserType {
if (name == null || this.options.userTypes == null) {
return null;
}
Expand Down