-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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/auth : NbOAuth2AuthStrategy implementing basic authentication scheme against token endpoints #582
feature/auth : NbOAuth2AuthStrategy implementing basic authentication scheme against token endpoints #582
Changes from 1 commit
843008e
e8d5de5
c5e61a3
10cefa8
7d5ed2f
70e73ce
b3c55a9
abca8ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
import { Inject, Injectable } from '@angular/core'; | ||
import { HttpClient, HttpErrorResponse } from '@angular/common/http'; | ||
import {HttpClient, HttpErrorResponse, HttpHeaders} from '@angular/common/http'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
import { Observable, of as observableOf } from 'rxjs'; | ||
import { switchMap, map, catchError } from 'rxjs/operators'; | ||
|
@@ -195,7 +195,7 @@ export class NbOAuth2AuthStrategy extends NbAuthStrategy { | |
refreshToken(token: NbAuthRefreshableToken): Observable<NbAuthResult> { | ||
const url = this.getActionEndpoint('refresh'); | ||
|
||
return this.http.post(url, this.buildRefreshRequestData(token)) | ||
return this.http.post(url, this.buildRefreshRequestData(token), this.buildRequestsHttpOptions()) | ||
.pipe( | ||
map((res) => { | ||
return new NbAuthResult( | ||
|
@@ -213,7 +213,7 @@ export class NbOAuth2AuthStrategy extends NbAuthStrategy { | |
passwordToken(email: string, password: string): Observable<NbAuthResult> { | ||
const url = this.getActionEndpoint('token'); | ||
|
||
return this.http.post(url, this.buildPasswordRequestData(email, password)) | ||
return this.http.post(url, this.buildPasswordRequestData(email, password), this.buildRequestsHttpOptions() ) | ||
.pipe( | ||
map((res) => { | ||
return new NbAuthResult( | ||
|
@@ -239,7 +239,7 @@ export class NbOAuth2AuthStrategy extends NbAuthStrategy { | |
protected requestToken(code: string) { | ||
const url = this.getActionEndpoint('token'); | ||
|
||
return this.http.post(url, this.buildCodeRequestData(code)) | ||
return this.http.post(url, this.buildCodeRequestData(code), this.buildRequestsHttpOptions()) | ||
.pipe( | ||
map((res) => { | ||
return new NbAuthResult( | ||
|
@@ -282,6 +282,20 @@ export class NbOAuth2AuthStrategy extends NbAuthStrategy { | |
return this.cleanParams(params); | ||
} | ||
|
||
protected buildRequestsHttpOptions(): any { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's make it optional? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes sense since clientId and clientSecret are optional There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, my comment was a bit misleading. What I meant is that probably we should add an option to the configuration as you proposed in the PR description indicating if we want to enable the base auth, pass clientid/cliensecret as body parameters or none of the above? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alain-charles just checking if you saw my comment :) |
||
let httpOptions: any = {}; | ||
if (this.getOption('clientId') && this.getOption('clientSecret')) { | ||
httpOptions = { | ||
headers: new HttpHeaders ( | ||
{ | ||
'Authorization' : 'Basic ' + btoa( | ||
this.getOption('clientId') + ':' + this.getOption('clientSecret')), | ||
}, | ||
)}; | ||
} | ||
return httpOptions; | ||
} | ||
|
||
protected handleResponseError(res: any): Observable<NbAuthResult> { | ||
let errors = []; | ||
if (res instanceof HttpErrorResponse) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spaces