@@ -45,6 +45,10 @@
|
||||
"express": "^4.17.1",
|
||||
"express-promise-router": "^4.1.0",
|
||||
"express-session": "^1.17.1",
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
"fs-extra": "9.1.0",
|
||||
>>>>>>> 4d5fd11228 (first minor cleanups)
|
||||
"google-auth-library": "^7.2.0",
|
||||
"helmet": "^4.0.0",
|
||||
"jose": "^1.27.1",
|
||||
|
||||
@@ -13,5 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { createGcpIAPProvider } from './provider';
|
||||
export type { GcpIAPProviderOptions } from './provider';
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import express from 'express';
|
||||
|
||||
import { GcpIAPProvider } from './provider';
|
||||
import { AuthResponse } from '../types';
|
||||
import { GcpIAPProvider } from './provider';
|
||||
|
||||
jest.mock('google-auth-library');
|
||||
|
||||
@@ -57,22 +57,22 @@ describe('GcpIAPProvider', () => {
|
||||
getEntityByName: jest.fn(),
|
||||
};
|
||||
|
||||
const mockRequest = ({
|
||||
const mockRequest = {
|
||||
header: jest.fn(() => {
|
||||
return 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImZvbyIsImlzcyI6ImZvbyJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.T2BNS4G-6RoiFnXc8Q8TiwdWzTpNitY8jcsGM3N3-Yo';
|
||||
}),
|
||||
} as unknown) as express.Request;
|
||||
const mockRequestWithoutJwt = ({
|
||||
} as unknown as express.Request;
|
||||
const mockRequestWithoutJwt = {
|
||||
header: jest.fn(() => {
|
||||
return undefined;
|
||||
}),
|
||||
} as unknown) as express.Request;
|
||||
const mockResponse = ({
|
||||
} as unknown as express.Request;
|
||||
const mockResponse = {
|
||||
end: jest.fn(),
|
||||
header: () => jest.fn(),
|
||||
json: jest.fn().mockReturnThis(),
|
||||
status: jest.fn(),
|
||||
} as unknown) as express.Response;
|
||||
} as unknown as express.Response;
|
||||
|
||||
describe('should transform to type OAuthResponse', () => {
|
||||
it('when JWT is valid and identity is resolved successfully', async () => {
|
||||
|
||||
@@ -14,19 +14,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { CatalogApi } from '@backstage/catalog-client';
|
||||
import express from 'express';
|
||||
import { OAuth2Client } from 'google-auth-library';
|
||||
import { Logger } from 'winston';
|
||||
import {
|
||||
AuthProviderRouteHandlers,
|
||||
AuthProviderFactory,
|
||||
AuthProviderFactoryOptions,
|
||||
AuthProviderRouteHandlers,
|
||||
ExperimentalIdentityResolver,
|
||||
} from '../types';
|
||||
|
||||
import express from 'express';
|
||||
|
||||
import { Logger } from 'winston';
|
||||
import { CatalogApi } from '@backstage/catalog-client';
|
||||
|
||||
import { OAuth2Client } from 'google-auth-library';
|
||||
|
||||
const IAP_JWT_HEADER = 'x-goog-iap-jwt-assertion';
|
||||
|
||||
export type GcpIAPProviderOptions = {
|
||||
@@ -47,6 +45,7 @@ export class GcpIAPProvider implements AuthProviderRouteHandlers {
|
||||
this.catalogClient = catalogClient;
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
frameHandler(): Promise<void> {
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
@@ -102,7 +101,9 @@ export class GcpIAPProvider implements AuthProviderRouteHandlers {
|
||||
}
|
||||
}
|
||||
|
||||
export const createGcpIAPProvider = (_options?: GcpIAPProviderOptions) => {
|
||||
export function createGcpIapProvider(
|
||||
_options?: GcpIAPProviderOptions,
|
||||
): AuthProviderFactory {
|
||||
return ({
|
||||
logger,
|
||||
catalogApi,
|
||||
@@ -111,13 +112,13 @@ export const createGcpIAPProvider = (_options?: GcpIAPProviderOptions) => {
|
||||
}: AuthProviderFactoryOptions) => {
|
||||
const audience = config.getString('audience');
|
||||
if (identityResolver !== undefined) {
|
||||
return new GcpIAPProvider(logger, catalogApi, {
|
||||
audience,
|
||||
identityResolutionCallback: identityResolver,
|
||||
});
|
||||
throw new Error(
|
||||
'Identity resolver is required to use this authentication provider',
|
||||
);
|
||||
}
|
||||
throw new Error(
|
||||
'Identity resolver is required to use this authentication provider',
|
||||
);
|
||||
return new GcpIAPProvider(logger, catalogApi, {
|
||||
audience,
|
||||
identityResolutionCallback: identityResolver,
|
||||
});
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user