Skip to content

Commit 038b462

Browse files
committed
Add more types in OAuthService
1 parent a1652dc commit 038b462

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

projects/lib/src/oauth-service.ts

+20-21
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
5454
* @internal
5555
* Deprecated: use property events instead
5656
*/
57-
public discoveryDocumentLoaded$: Observable<object>;
57+
public discoveryDocumentLoaded$: Observable<OidcDiscoveryDoc>;
5858

5959
/**
6060
* Informs about events, like token_received or token_expires.
@@ -69,7 +69,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
6969
public state? = '';
7070

7171
protected eventsSubject: Subject<OAuthEvent> = new Subject<OAuthEvent>();
72-
protected discoveryDocumentLoadedSubject: Subject<object> = new Subject<object>();
72+
protected discoveryDocumentLoadedSubject: Subject<OidcDiscoveryDoc> = new Subject<OidcDiscoveryDoc>();
7373
protected silentRefreshPostMessageEventListener: EventListener;
7474
protected grantTypesSupported: Array<string> = [];
7575
protected _storage: OAuthStorage;
@@ -128,7 +128,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
128128
* Use this method to configure the service
129129
* @param config the configuration
130130
*/
131-
public configure(config: AuthConfig) {
131+
public configure(config: AuthConfig): void {
132132
// For the sake of downward compatibility with
133133
// original configuration API
134134
Object.assign(this, new AuthConfig(), config);
@@ -156,7 +156,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
156156
this.setupExpirationTimers();
157157
}
158158

159-
protected setupSessionCheck() {
159+
protected setupSessionCheck(): void {
160160
this.events.pipe(filter(e => e.type === 'token_received')).subscribe(e => {
161161
this.initSessionCheck();
162162
});
@@ -170,7 +170,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
170170
* @param params Additional parameter to pass
171171
* @param listenTo Setup automatic refresh of a specific token type
172172
*/
173-
public setupAutomaticSilentRefresh(params: object = {}, listenTo?: 'access_token' | 'id_token' | 'any', noPrompt = true) {
173+
public setupAutomaticSilentRefresh(params: object = {}, listenTo?: 'access_token' | 'id_token' | 'any', noPrompt = true): void {
174174
let shouldRunSilentRefresh = true;
175175
this.events.pipe(
176176
tap((e) => {
@@ -194,7 +194,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
194194
this.restartRefreshTimerIfStillLoggedIn();
195195
}
196196

197-
protected refreshInternal(params, noPrompt) {
197+
protected refreshInternal(params, noPrompt): Promise<TokenResponse|OAuthEvent> {
198198
if (this.responseType === 'code') {
199199
return this.refreshToken();
200200
} else {
@@ -405,7 +405,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
405405
*
406406
* @param fullUrl
407407
*/
408-
public loadDiscoveryDocument(fullUrl: string = null): Promise<object> {
408+
public loadDiscoveryDocument(fullUrl: string = null): Promise<OAuthSuccessEvent> {
409409
return new Promise((resolve, reject) => {
410410
if (!fullUrl) {
411411
fullUrl = this.issuer || '';
@@ -586,7 +586,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
586586
userName: string,
587587
password: string,
588588
headers: HttpHeaders = new HttpHeaders()
589-
): Promise<object> {
589+
): Promise<UserInfo> {
590590
return this.fetchTokenUsingPasswordFlow(userName, password, headers).then(
591591
() => this.loadUserProfile()
592592
);
@@ -598,7 +598,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
598598
* When using this with OAuth2 password flow, make sure that the property oidc is set to false.
599599
* Otherwise stricter validations take place that make this operation fail.
600600
*/
601-
public loadUserProfile(): Promise<object> {
601+
public loadUserProfile(): Promise<UserInfo> {
602602
if (!this.hasValidAccessToken()) {
603603
throw new Error('Can not load User Profile without access_token');
604604
}
@@ -662,7 +662,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
662662
userName: string,
663663
password: string,
664664
headers: HttpHeaders = new HttpHeaders()
665-
): Promise<object> {
665+
): Promise<TokenResponse> {
666666
if (!this.validateUrlForHttps(this.tokenEndpoint)) {
667667
throw new Error(
668668
'tokenEndpoint must use https, or config value for property requireHttps must allow http'
@@ -739,7 +739,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
739739
* A solution for this is provided by the
740740
* method silentRefresh.
741741
*/
742-
public refreshToken(): Promise<object> {
742+
public refreshToken(): Promise<TokenResponse> {
743743

744744
if (!this.validateUrlForHttps(this.tokenEndpoint)) {
745745
throw new Error(
@@ -954,7 +954,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
954954
});
955955
}
956956

957-
protected calculatePopupFeatures(options: { height?: number, width?: number }) {
957+
protected calculatePopupFeatures(options: { height?: number, width?: number }): string {
958958
// Specify an static height and width and calculate centered position
959959
const height = options.height || 470;
960960
const width = options.width || 500;
@@ -963,7 +963,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
963963
return `location=no,toolbar=no,width=${width},height=${height},top=${top},left=${left}`;
964964
}
965965

966-
protected processMessageEventMessage(e: MessageEvent) {
966+
protected processMessageEventMessage(e: MessageEvent): string {
967967
let expectedPrefix = '#';
968968

969969
if (this.silentRefreshMessagePrefix) {
@@ -1071,7 +1071,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
10711071
}
10721072
}
10731073

1074-
protected waitForSilentRefreshAfterSessionChange() {
1074+
protected waitForSilentRefreshAfterSessionChange(): void {
10751075
this.events
10761076
.pipe(
10771077
filter(
@@ -1169,7 +1169,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
11691169
customRedirectUri = '',
11701170
noPrompt = false,
11711171
params: object = {}
1172-
) {
1172+
): Promise<string> {
11731173
const that = this;
11741174

11751175
let redirectUri: string;
@@ -1264,7 +1264,6 @@ export class OAuthService extends AuthConfig implements OnDestroy {
12641264
}
12651265

12661266
return url;
1267-
12681267
}
12691268

12701269
initImplicitFlowInternal(
@@ -1448,7 +1447,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
14481447
/**
14491448
* Get token using an intermediate code. Works for the Authorization Code flow.
14501449
*/
1451-
private getTokenFromCode(code: string): Promise<object> {
1450+
private getTokenFromCode(code: string): Promise<TokenResponse> {
14521451
let params = new HttpParams()
14531452
.set('grant_type', 'authorization_code')
14541453
.set('code', code)
@@ -1467,7 +1466,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
14671466
return this.fetchAndProcessToken(params);
14681467
}
14691468

1470-
private fetchAndProcessToken(params: HttpParams): Promise<object> {
1469+
private fetchAndProcessToken(params: HttpParams): Promise<TokenResponse> {
14711470

14721471
let headers = new HttpHeaders()
14731472
.set('Content-Type', 'application/x-www-form-urlencoded');
@@ -1696,7 +1695,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
16961695
return true;
16971696
}
16981697

1699-
protected storeIdToken(idToken: ParsedIdToken) {
1698+
protected storeIdToken(idToken: ParsedIdToken): void {
17001699
this._storage.setItem('id_token', idToken.idToken);
17011700
this._storage.setItem('id_token_claims_obj', idToken.idTokenClaimsJson);
17021701
this._storage.setItem('id_token_expires_at', '' + idToken.idTokenExpiresAt);
@@ -2070,7 +2069,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
20702069
/**
20712070
* @ignore
20722071
*/
2073-
public ngOnDestroy() {
2072+
public ngOnDestroy(): void {
20742073
this.clearAccessTokenTimer();
20752074
this.clearIdTokenTimer();
20762075
}
@@ -2135,7 +2134,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
21352134
public initLoginFlow(
21362135
additionalState = '',
21372136
params = {}
2138-
) {
2137+
): void {
21392138
if (this.responseType === 'code') {
21402139
return this.initCodeFlow(additionalState, params);
21412140
} else {

0 commit comments

Comments
 (0)