fix(self-service): update API to leverage current HTTP interceptors (#124)
Update API for self service user management to leverage current HTTP interceptors for setting the API prefix and request headers. Fixes #123
This commit is contained in:
@@ -92,16 +92,13 @@ export class AuthenticationService {
|
|||||||
this.storage = this.rememberMe ? localStorage : sessionStorage;
|
this.storage = this.rememberMe ? localStorage : sessionStorage;
|
||||||
|
|
||||||
if (environment.oauth.enabled) {
|
if (environment.oauth.enabled) {
|
||||||
return this.http.disableApiPrefix().post(
|
return this.http.disableApiPrefix().post(`${environment.oauth.serverUrl}/oauth/token?username=${loginContext.username}&password=${loginContext.password}&client_id=community-app&grant_type=password&client_secret=123`, {})
|
||||||
`${environment.oauth.serverUrl}
|
.pipe(
|
||||||
/oauth/token?username=${loginContext.username}&password=${loginContext.password}
|
map((tokenResponse: OAuth2Token) => {
|
||||||
&client_id=community-app&grant_type=password&client_secret=123`, {}
|
this.getUserDetails(tokenResponse);
|
||||||
).pipe(
|
return of(true);
|
||||||
map((tokenResponse: OAuth2Token) => {
|
})
|
||||||
this.getUserDetails(tokenResponse);
|
);
|
||||||
return of(true);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
return this.http.post(`/authentication?username=${loginContext.username}&password=${loginContext.password}`, {})
|
return this.http.post(`/authentication?username=${loginContext.username}&password=${loginContext.password}`, {})
|
||||||
.pipe(
|
.pipe(
|
||||||
@@ -131,11 +128,8 @@ export class AuthenticationService {
|
|||||||
refreshOAuthAccessToken() {
|
refreshOAuthAccessToken() {
|
||||||
const oAuthRefreshToken = JSON.parse(this.storage.getItem(oAuthTokenDetailsStorageKey)).refresh_token;
|
const oAuthRefreshToken = JSON.parse(this.storage.getItem(oAuthTokenDetailsStorageKey)).refresh_token;
|
||||||
this.authenticationInterceptor.removeAuthorization();
|
this.authenticationInterceptor.removeAuthorization();
|
||||||
this.http.disableApiPrefix().post(
|
this.http.disableApiPrefix().post(`${environment.oauth.serverUrl}/oauth/token?client_id=community-app&grant_type=refresh_token&client_secret=123&refresh_token=${oAuthRefreshToken}`, {})
|
||||||
`${environment.oauth.serverUrl}
|
.subscribe((tokenResponse: OAuth2Token) => {
|
||||||
/oauth/token?client_id=community-app&grant_type=refresh_token&client_secret=123
|
|
||||||
&refresh_token=${oAuthRefreshToken}`, {}
|
|
||||||
).subscribe((tokenResponse: OAuth2Token) => {
|
|
||||||
this.storage.setItem(oAuthTokenDetailsStorageKey, JSON.stringify(tokenResponse));
|
this.storage.setItem(oAuthTokenDetailsStorageKey, JSON.stringify(tokenResponse));
|
||||||
this.authenticationInterceptor.setAuthorizationToken(tokenResponse.access_token);
|
this.authenticationInterceptor.setAuthorizationToken(tokenResponse.access_token);
|
||||||
this.refreshTokenOnExpiry(tokenResponse.expires_in);
|
this.refreshTokenOnExpiry(tokenResponse.expires_in);
|
||||||
|
|||||||
@@ -1,21 +1,8 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpHeaders, HttpClient } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { Observable } from 'rxjs/internal/Observable';
|
import { Observable } from 'rxjs/internal/Observable';
|
||||||
import { map } from 'rxjs/internal/operators/map';
|
import { map } from 'rxjs/internal/operators/map';
|
||||||
|
|
||||||
const username = 'mifos';
|
|
||||||
const password = 'password';
|
|
||||||
const token = btoa(`${username}:${password}`);
|
|
||||||
|
|
||||||
const httpOptions = {
|
|
||||||
headers: new HttpHeaders({
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Authorization': `Basic ${token}`,
|
|
||||||
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
|
|
||||||
'Access-Control-Allow-Origin': '*'
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
@@ -24,20 +11,18 @@ export class UserService {
|
|||||||
constructor(private http: HttpClient) { }
|
constructor(private http: HttpClient) { }
|
||||||
|
|
||||||
getUsers(): Observable<any> {
|
getUsers(): Observable<any> {
|
||||||
return this.http.get<any>(
|
return this.http.get<any>(`/users?fields=id,firstname,lastname,email,officeName,staff&tenantIdentifier=default&pretty=true`)
|
||||||
`https://demo.openmf.org/fineract-provider/api/v1/users?
|
.pipe(
|
||||||
fields=id,firstname,lastname,email,officeName,staff&tenantIdentifier=default&pretty=true`,
|
map((res) => {
|
||||||
httpOptions).pipe(
|
res.forEach((user: any) => {
|
||||||
map((res) => {
|
user.name = `${user.firstname} ${user.lastname}`;
|
||||||
res.forEach((user: any) => {
|
user.staff = user.staff ? `${user.staff.firstname} ${user.staff.lastname}` : '';
|
||||||
user.name = `${user.firstname} ${user.lastname}`;
|
delete user.firstname;
|
||||||
user.staff = user.staff ? `${user.staff.firstname} ${user.staff.lastname}` : '';
|
delete user.lastname;
|
||||||
delete user.firstname;
|
});
|
||||||
delete user.lastname;
|
return res;
|
||||||
});
|
})
|
||||||
return res;
|
);
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -30,7 +30,7 @@
|
|||||||
"label-position": true,
|
"label-position": true,
|
||||||
"max-line-length": [
|
"max-line-length": [
|
||||||
true,
|
true,
|
||||||
135
|
250
|
||||||
],
|
],
|
||||||
"member-access": false,
|
"member-access": false,
|
||||||
"member-ordering": [
|
"member-ordering": [
|
||||||
|
|||||||
Reference in New Issue
Block a user