Browse Source

Reformat and change AbstractModel name to AuthResponse

pull/15788/head
Mahmut Gundogdu 3 years ago
parent
commit
2f5ad652f8
  1. 5
      npm/ng-packs/packages/core/src/lib/abstracts/auth-response.model.ts
  2. 32
      npm/ng-packs/packages/core/src/lib/abstracts/auth.service.ts
  3. 2
      npm/ng-packs/packages/core/src/lib/abstracts/index.ts
  4. 42
      npm/ng-packs/packages/oauth/src/lib/services/oauth.service.ts

5
npm/ng-packs/packages/core/src/lib/abstracts/abstract.model.ts → npm/ng-packs/packages/core/src/lib/abstracts/auth-response.model.ts

@ -1,4 +1,4 @@
export interface AbstractModel { export interface AbpAuthResponse {
access_token: string; access_token: string;
id_token: string; id_token: string;
token_type: string; token_type: string;
@ -6,6 +6,5 @@ export interface AbstractModel {
refresh_token: string; refresh_token: string;
scope: string; scope: string;
state?: string; state?: string;
tenant_domain?:string tenant_domain?: string;
} }

32
npm/ng-packs/packages/core/src/lib/abstracts/auth.service.ts

@ -1,9 +1,9 @@
import {HttpHeaders} from '@angular/common/http'; import { HttpHeaders } from '@angular/common/http';
import {Injectable} from '@angular/core'; import { Injectable } from '@angular/core';
import {Params} from '@angular/router'; import { Params } from '@angular/router';
import {Observable, of} from 'rxjs'; import { Observable, of } from 'rxjs';
import {LoginParams} from '../models/auth'; import { LoginParams } from '../models/auth';
import {AbstractModel} from "./abstract.model"; import { AbpAuthResponse } from './auth-response.model';
/** /**
* Abstract service for Authentication. * Abstract service for Authentication.
@ -12,9 +12,6 @@ import {AbstractModel} from "./abstract.model";
providedIn: 'root', providedIn: 'root',
}) })
export class AuthService implements IAuthService { export class AuthService implements IAuthService {
constructor() {
}
private warningMessage() { private warningMessage() {
console.error('You should add @abp/ng-oauth packages or create your own auth packages.'); console.error('You should add @abp/ng-oauth packages or create your own auth packages.');
} }
@ -34,8 +31,7 @@ export class AuthService implements IAuthService {
return of(undefined); return of(undefined);
} }
navigateToLogin(queryParams?: Params): void { navigateToLogin(queryParams?: Params): void {}
}
get isInternalAuth() { get isInternalAuth() {
throw new Error('not implemented'); throw new Error('not implemented');
@ -47,8 +43,12 @@ export class AuthService implements IAuthService {
return false; return false;
} }
loginUsingGrant(grantType: string, parameters: object, headers?: HttpHeaders): Promise<AbstractModel> { loginUsingGrant(
console.log({grantType, parameters, headers}) grantType: string,
parameters: object,
headers?: HttpHeaders,
): Promise<AbpAuthResponse> {
console.log({ grantType, parameters, headers });
return Promise.reject(new Error('not implemented')); return Promise.reject(new Error('not implemented'));
} }
} }
@ -66,5 +66,9 @@ export interface IAuthService {
login(params: LoginParams): Observable<any>; login(params: LoginParams): Observable<any>;
loginUsingGrant(grantType: string, parameters: object, headers?: HttpHeaders): Promise<AbstractModel>; loginUsingGrant(
grantType: string,
parameters: object,
headers?: HttpHeaders,
): Promise<AbpAuthResponse>;
} }

2
npm/ng-packs/packages/core/src/lib/abstracts/index.ts

@ -1,4 +1,4 @@
export * from './ng-model.component'; export * from './ng-model.component';
export * from './auth.guard'; export * from './auth.guard';
export * from './auth.service'; export * from './auth.service';
export * from './abstract.model' export * from './auth-response.model';

42
npm/ng-packs/packages/oauth/src/lib/services/oauth.service.ts

@ -1,26 +1,27 @@
import {Injectable, Injector} from '@angular/core'; import { Injectable, Injector } from '@angular/core';
import {Params} from '@angular/router'; import { Params } from '@angular/router';
import {from, Observable, lastValueFrom} from 'rxjs'; import { from, Observable, lastValueFrom } from 'rxjs';
import {filter, map, switchMap, take, tap} from 'rxjs/operators'; import { filter, map, switchMap, take, tap } from 'rxjs/operators';
import { AbstractModel, IAuthService, LoginParams} from '@abp/ng.core'; import { AbpAuthResponse, IAuthService, LoginParams } from '@abp/ng.core';
import {AuthFlowStrategy} from '../strategies'; import { AuthFlowStrategy } from '../strategies';
import {EnvironmentService} from '@abp/ng.core'; import { EnvironmentService } from '@abp/ng.core';
import {AUTH_FLOW_STRATEGY} from '../tokens/auth-flow-strategy'; import { AUTH_FLOW_STRATEGY } from '../tokens/auth-flow-strategy';
import {OAuthService} from "angular-oauth2-oidc"; import { OAuthService } from 'angular-oauth2-oidc';
import {HttpHeaders} from '@angular/common/http'; import { HttpHeaders } from '@angular/common/http';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
}) })
export class AbpOAuthService implements IAuthService { export class AbpOAuthService implements IAuthService {
private strategy!: AuthFlowStrategy; private strategy!: AuthFlowStrategy;
private oAuthService: OAuthService; private readonly oAuthService: OAuthService;
get isInternalAuth() { get isInternalAuth() {
return this.strategy.isInternalAuth; return this.strategy.isInternalAuth;
} }
constructor(protected injector: Injector,) { constructor(protected injector: Injector) {
this.oAuthService = this.injector.get(OAuthService) this.oAuthService = this.injector.get(OAuthService);
} }
async init() { async init() {
@ -58,21 +59,24 @@ export class AbpOAuthService implements IAuthService {
return this.oAuthService.hasValidAccessToken(); return this.oAuthService.hasValidAccessToken();
} }
loginUsingGrant(grantType: string, parameters: object, headers?: HttpHeaders): Promise<AbstractModel> { loginUsingGrant(
grantType: string,
const {clientId: client_id, dummyClientSecret: client_secret} = this.oAuthService; parameters: object,
const access_token = this.oAuthService.getAccessToken() headers?: HttpHeaders,
): Promise<AbpAuthResponse> {
const { clientId: client_id, dummyClientSecret: client_secret } = this.oAuthService;
const access_token = this.oAuthService.getAccessToken();
const p = { const p = {
access_token, access_token,
grant_type: grantType, grant_type: grantType,
client_id, client_id,
...parameters ...parameters,
}; };
if (client_secret) { if (client_secret) {
p['client_secret'] = client_secret; p['client_secret'] = client_secret;
} }
return this.oAuthService.fetchTokenUsingGrant(grantType, p, headers) return this.oAuthService.fetchTokenUsingGrant(grantType, p, headers);
} }
} }

Loading…
Cancel
Save