Reputation: 23247
I'm developing a library in order to get access to a REST ednpoint.
I've generated a Injectable class foreach REST endpoint (you can take a look on here. Now, I need to add OAuth dance to this callings, and I've thought to create a OAuthService
class:
import { Injectable } from '@angular/core';
import { Http, Headers, URLSearchParams } from '@angular/http';
import { OAuthSettings } from './OAuthSettings';
@Injectable()
export class OAuthService
{
constructor(private http: Http, private settings: OAuthSettings) { }
grantAuthorization() {}
getAccessToken() {}
refreshAccessToken() {}
}
, where OAuthSettings
is:
export class OAuthSettings {
baseAuthzURI: string;
baseCESTURI: string;
client: string;
user: string;
passwd: string;
authzCode: string;
accessToken: string;
refreshToken: string;
authCodeThreshold: Date;
accessTokenThreshold: Date;
refreshTokenThreshold: Date;
}
I'm able to figure out that I need to add an OAuthService
on UserApi
as dependency. But, what about OAuthSettings
, how is this provided, or initialized?
This library it's used by an application which's going to need to provide an user and a password. So, these fields have to be provided on OAuthSettings
by someway.
Upvotes: 1
Views: 530
Reputation: 657376
@NgModule({
providers: [{ provide: OAuthSettings, useValue: {...}}]
Upvotes: 2