diff --git a/docs/blog/version-5.0-release-notes.md b/docs/blog/version-5.0-release-notes.md index 08ca0fdbab..7b12c8bc95 100644 --- a/docs/blog/version-5.0-release-notes.md +++ b/docs/blog/version-5.0-release-notes.md @@ -63,6 +63,8 @@ Version 5.0 of [Foal](https://foalts.org/) is out! ``` +- The return value of the social services `getUserInfoFromTokens` method is now typed. + ## Removal of deprecated components - The deprecated hook `@Log` has been removed. Use the `Logger` service in a custom `@Hook` instead. diff --git a/docs/docs/authentication/social-auth.md b/docs/docs/authentication/social-auth.md index 588c1549be..50382b06d1 100644 --- a/docs/docs/authentication/social-auth.md +++ b/docs/docs/authentication/social-auth.md @@ -343,7 +343,11 @@ export interface GithubUserInfoParameter { // ... } -export class GithubProvider extends AbstractProvider { +export interface GithubUserInfo { + // ... +} + +export class GithubProvider extends AbstractProvider { protected configPaths = { clientId: 'social.github.clientId', @@ -357,7 +361,7 @@ export class GithubProvider extends AbstractProvider { // ... // In case the server returns an error when requesting diff --git a/packages/social/src/abstract-provider.service.spec.ts b/packages/social/src/abstract-provider.service.spec.ts index 0275a36c35..f8e6d74970 100644 --- a/packages/social/src/abstract-provider.service.spec.ts +++ b/packages/social/src/abstract-provider.service.spec.ts @@ -143,7 +143,7 @@ describe('TokenError', () => { describe('AbstractProvider', () => { - class ConcreteProvider extends AbstractProvider { + class ConcreteProvider extends AbstractProvider { protected configPaths = { clientId: 'settings.social.example.clientId', clientSecret: 'settings.social.example.clientSecret', @@ -151,7 +151,8 @@ describe('AbstractProvider', () => { }; protected authEndpoint = 'https://example2.com/auth'; protected tokenEndpoint = 'http://localhost:3000/token'; - getUserInfoFromTokens(tokens: SocialTokens) { + + async getUserInfoFromTokens(tokens: SocialTokens): Promise { throw new Error('Method not implemented.'); } } @@ -611,7 +612,7 @@ describe('AbstractProvider', () => { }); class ConcreteProvider2 extends ConcreteProvider { - getUserInfoFromTokens(tokens: SocialTokens) { + async getUserInfoFromTokens(tokens: SocialTokens) { // Do not throw an error. } } @@ -656,7 +657,7 @@ describe('AbstractProvider', () => { let calledWithTokens: null|SocialTokens = null; let calledWithParams: null|any = null; class ConcreteProvider2 extends ConcreteProvider { - getUserInfoFromTokens(tokens: SocialTokens, params?: any) { + async getUserInfoFromTokens(tokens: SocialTokens, params?: any) { calledWithTokens = tokens; calledWithParams = params || null; } @@ -718,7 +719,8 @@ describe('Abstract Provider With PKCE', () => { protected usePKCE: boolean = true; protected authEndpoint = 'https://example2.com/auth'; protected tokenEndpoint = 'http://localhost:3000/token'; - getUserInfoFromTokens(tokens: SocialTokens) { + + async getUserInfoFromTokens(tokens: SocialTokens) { throw new Error('Method not implemented.'); } } @@ -917,7 +919,8 @@ describe('Abstract Provider With PKCE and Plain Method', () => { protected useCodeVerifierAsCodeChallenge = true; protected authEndpoint = 'https://example2.com/auth'; protected tokenEndpoint = 'http://localhost:3000/token'; - getUserInfoFromTokens(tokens: SocialTokens) { + + async getUserInfoFromTokens(tokens: SocialTokens) { throw new Error('Method not implemented.'); } } diff --git a/packages/social/src/abstract-provider.service.ts b/packages/social/src/abstract-provider.service.ts index 6297dc5ab5..55008dcf6d 100644 --- a/packages/social/src/abstract-provider.service.ts +++ b/packages/social/src/abstract-provider.service.ts @@ -113,9 +113,9 @@ export interface ObjectType { * @class AbstractProvider * @template AuthParameters - Additional parameters to pass to the auth endpoint. * @template UserInfoParameters - Additional parameters to pass when retrieving user information. - * @template IUserInfo - Type of the user information. + * @template UserInfo - Type of the user information. */ -export abstract class AbstractProvider { +export abstract class AbstractProvider { /** * Configuration paths from which the client ID, client secret and redirect URI must be retrieved. @@ -232,10 +232,10 @@ export abstract class AbstractProvider} The user information. * @memberof AbstractProvider */ - abstract getUserInfoFromTokens(tokens: SocialTokens, params?: UserInfoParameters): any; + abstract getUserInfoFromTokens(tokens: SocialTokens, params?: UserInfoParameters): UserInfo | Promise; /** * Returns an HttpResponseOK or HttpResponseRedirect object to redirect the user to the social provider's authorization page. @@ -393,13 +393,12 @@ export abstract class AbstractProvider>} The access token and the user information * @memberof AbstractProvider */ - async getUserInfo(ctx: Context, params?: UserInfoParameters): Promise> { + async getUserInfo(ctx: Context, params?: UserInfoParameters): Promise> { const tokens = await this.getTokens(ctx); const userInfo = await this.getUserInfoFromTokens(tokens, params); return { userInfo, tokens }; diff --git a/packages/social/src/google-provider.service.ts b/packages/social/src/google-provider.service.ts index faf5c4ead2..bf412898f9 100644 --- a/packages/social/src/google-provider.service.ts +++ b/packages/social/src/google-provider.service.ts @@ -57,7 +57,7 @@ export class GoogleProvider extends AbstractProvider