Skip to content

Commit

Permalink
fix(oidc): ensure Origin can be set on call to IDPs
Browse files Browse the repository at this point in the history
  • Loading branch information
JMounier committed May 2, 2024
1 parent 89ff21f commit 6ce042d
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions packages/core/src/Network/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,17 @@ export class Client {
// Simple _fetch wrapper with:
// - proper headers set (sdk info and authorization)
// - generic error handling
_baseApiCall = async (path: string, authenticated: boolean, init?: RequestInit): Promise<any> => {
try {
if (!path || path[0] !== '/') {
throw new InvalidArgument('"path" should be non empty and start with "/"');
}
_baseApiCall = (path: string, authenticated: boolean, init?: RequestInit): Promise<any> => {
if (!path || path[0] !== '/') {
throw new InvalidArgument('"path" should be non empty and start with "/"');
}
const url = `${this._apiEndpoint}${this._apiRootPath}${path}`;

return this._basehttpCall(url, authenticated, init);
};

_basehttpCall = async (url: string, authenticated: boolean, init?: RequestInit): Promise<any> => {
try {
const headers = (init?.headers ? init.headers : {}) as Record<string, string>;
headers['X-Tanker-Instanceid'] = this._instanceId;
headers['X-Tanker-Sdktype'] = this._sdkType;
Expand All @@ -119,7 +124,6 @@ export class Client {
headers['Authorization'] = `Bearer ${this._accessToken}`; // eslint-disable-line dot-notation
}

const url = `${this._apiEndpoint}${this._apiRootPath}${path}`;

const response = await this._fetch(url, { ...init, headers });

Expand Down Expand Up @@ -448,11 +452,20 @@ export class Client {
};

oidcSignIn = async (oidcProviderId: string): Promise<OidcAuthorizationCodeVerification> => {
const { code, state } = await this._baseApiCall(
const resp = await this._baseApiCall(
`/oidc/${oidcProviderId}/signin?user_id=${urlize(this._userId)}`,
false,
{ credentials: 'include' },
);

const { location } = resp;

const { code, state } = await this._basehttpCall(
location,
false,
{ credentials: 'include' },
);

return {
oidcProviderId,
oidcAuthorizationCode: code,
Expand Down

0 comments on commit 6ce042d

Please sign in to comment.