Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
Expose the api to fetch userinfo (#1381)
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriziovitale authored May 10, 2022
1 parent c7273a2 commit e19d6ce
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/authentication/oauth2Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,20 @@ const minimatch = require('minimatch');

declare let window: Window;

interface Userinfo {
name: string;
given_name?: string;
family_name?: string;
preferred_username?: string;
email?: string;
picture?: string;
}

export class Oauth2Auth extends AlfrescoApiClient {

static readonly DEFAULT_AUTHORIZATION_URL = '/protocol/openid-connect/auth';
static readonly DEFAULT_TOKEN_URL = '/protocol/openid-connect/token';
static readonly DEFAULT_USER_INFO_ENDPOINT = '/protocol/openid-connect/userinfo';
static readonly DEFAULT_LOGOUT_URL = '/protocol/openid-connect/logout';

private refreshTokenIntervalPolling: any;
Expand All @@ -47,10 +57,12 @@ export class Oauth2Auth extends AlfrescoApiClient {
loginUrl?: string;
logoutUrl?: string;
tokenEndpoint?: string;
userinfoEndpoint?: string;
} = {
loginUrl: undefined,
logoutUrl: undefined,
tokenEndpoint: undefined,
userinfoEndpoint: undefined,
};

authentications: Authentication = {
Expand Down Expand Up @@ -136,6 +148,27 @@ export class Oauth2Auth extends AlfrescoApiClient {
this.discovery.loginUrl = this.config.oauth2.authorizationUrl || this.host + Oauth2Auth.DEFAULT_AUTHORIZATION_URL;
this.discovery.logoutUrl = this.config.oauth2.logoutUrl || this.host + Oauth2Auth.DEFAULT_LOGOUT_URL;
this.discovery.tokenEndpoint = this.config.oauth2.tokenUrl || this.host + Oauth2Auth.DEFAULT_TOKEN_URL;
this.discovery.userinfoEndpoint = this.config.oauth2.userinfoEndpoint || this.host + Oauth2Auth.DEFAULT_USER_INFO_ENDPOINT;
}

getProfile(): Promise<Userinfo> {
const postBody = {}, pathParams = {}, queryParams = {};

const headerParams = {
'Content-Type': 'application/x-www-form-urlencoded'
};

const formParams = {
};

const contentTypes = ['application/x-www-form-urlencoded'];
const accepts = ['application/json'];

return this.callCustomApi(
this.discovery.userinfoEndpoint, 'GET',
pathParams, queryParams, headerParams, formParams, postBody,
contentTypes, accepts
);
}

hasContentProvider(): boolean {
Expand Down
1 change: 1 addition & 0 deletions src/authentication/oauth2Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface Oauth2Config {
host: string;
authorizationUrl?: string;
tokenUrl?: string;
userinfoEndpoint?: string;
logoutUrl?: string;
scope: string;
implicitFlow?: boolean;
Expand Down

0 comments on commit e19d6ce

Please sign in to comment.