Skip to content

Commit 60e2c6c

Browse files
Merge pull request #684 from vadjs/master
Add more types in OAuthService
2 parents 10441f1 + 038b462 commit 60e2c6c

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 {
@@ -409,7 +409,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
409409
*
410410
* @param fullUrl
411411
*/
412-
public loadDiscoveryDocument(fullUrl: string = null): Promise<object> {
412+
public loadDiscoveryDocument(fullUrl: string = null): Promise<OAuthSuccessEvent> {
413413
return new Promise((resolve, reject) => {
414414
if (!fullUrl) {
415415
fullUrl = this.issuer || '';
@@ -590,7 +590,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
590590
userName: string,
591591
password: string,
592592
headers: HttpHeaders = new HttpHeaders()
593-
): Promise<object> {
593+
): Promise<UserInfo> {
594594
return this.fetchTokenUsingPasswordFlow(userName, password, headers).then(
595595
() => this.loadUserProfile()
596596
);
@@ -602,7 +602,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
602602
* When using this with OAuth2 password flow, make sure that the property oidc is set to false.
603603
* Otherwise stricter validations take place that make this operation fail.
604604
*/
605-
public loadUserProfile(): Promise<object> {
605+
public loadUserProfile(): Promise<UserInfo> {
606606
if (!this.hasValidAccessToken()) {
607607
throw new Error('Can not load User Profile without access_token');
608608
}
@@ -666,7 +666,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
666666
userName: string,
667667
password: string,
668668
headers: HttpHeaders = new HttpHeaders()
669-
): Promise<object> {
669+
): Promise<TokenResponse> {
670670
if (!this.validateUrlForHttps(this.tokenEndpoint)) {
671671
throw new Error(
672672
'tokenEndpoint must use https, or config value for property requireHttps must allow http'
@@ -743,7 +743,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
743743
* A solution for this is provided by the
744744
* method silentRefresh.
745745
*/
746-
public refreshToken(): Promise<object> {
746+
public refreshToken(): Promise<TokenResponse> {
747747

748748
if (!this.validateUrlForHttps(this.tokenEndpoint)) {
749749
throw new Error(
@@ -958,7 +958,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
958958
});
959959
}
960960

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

970-
protected processMessageEventMessage(e: MessageEvent) {
970+
protected processMessageEventMessage(e: MessageEvent): string {
971971
let expectedPrefix = '#';
972972

973973
if (this.silentRefreshMessagePrefix) {
@@ -1075,7 +1075,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
10751075
}
10761076
}
10771077

1078-
protected waitForSilentRefreshAfterSessionChange() {
1078+
protected waitForSilentRefreshAfterSessionChange(): void {
10791079
this.events
10801080
.pipe(
10811081
filter(
@@ -1173,7 +1173,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
11731173
customRedirectUri = '',
11741174
noPrompt = false,
11751175
params: object = {}
1176-
) {
1176+
): Promise<string> {
11771177
const that = this;
11781178

11791179
let redirectUri: string;
@@ -1268,7 +1268,6 @@ export class OAuthService extends AuthConfig implements OnDestroy {
12681268
}
12691269

12701270
return url;
1271-
12721271
}
12731272

12741273
initImplicitFlowInternal(
@@ -1452,7 +1451,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
14521451
/**
14531452
* Get token using an intermediate code. Works for the Authorization Code flow.
14541453
*/
1455-
private getTokenFromCode(code: string): Promise<object> {
1454+
private getTokenFromCode(code: string): Promise<TokenResponse> {
14561455
let params = new HttpParams()
14571456
.set('grant_type', 'authorization_code')
14581457
.set('code', code)
@@ -1471,7 +1470,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
14711470
return this.fetchAndProcessToken(params);
14721471
}
14731472

1474-
private fetchAndProcessToken(params: HttpParams): Promise<object> {
1473+
private fetchAndProcessToken(params: HttpParams): Promise<TokenResponse> {
14751474

14761475
let headers = new HttpHeaders()
14771476
.set('Content-Type', 'application/x-www-form-urlencoded');
@@ -1700,7 +1699,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
17001699
return true;
17011700
}
17021701

1703-
protected storeIdToken(idToken: ParsedIdToken) {
1702+
protected storeIdToken(idToken: ParsedIdToken): void {
17041703
this._storage.setItem('id_token', idToken.idToken);
17051704
this._storage.setItem('id_token_claims_obj', idToken.idTokenClaimsJson);
17061705
this._storage.setItem('id_token_expires_at', '' + idToken.idTokenExpiresAt);
@@ -2092,7 +2091,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
20922091
/**
20932092
* @ignore
20942093
*/
2095-
public ngOnDestroy() {
2094+
public ngOnDestroy(): void {
20962095
this.clearAccessTokenTimer();
20972096
this.clearIdTokenTimer();
20982097
}
@@ -2157,7 +2156,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
21572156
public initLoginFlow(
21582157
additionalState = '',
21592158
params = {}
2160-
) {
2159+
): void {
21612160
if (this.responseType === 'code') {
21622161
return this.initCodeFlow(additionalState, params);
21632162
} else {

0 commit comments

Comments
 (0)