auth-backend: move passport helpers into separate lib
This commit is contained in:
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
|
||||
import express from 'express';
|
||||
import { AuthResponse } from '../../providers/types';
|
||||
import { RedirectInfo } from '../PassportStrategyHelper';
|
||||
import { AuthResponse, RedirectInfo } from '../../providers/types';
|
||||
|
||||
/**
|
||||
* Common options for passport.js-based OAuth providers
|
||||
|
||||
+1
-12
@@ -17,7 +17,7 @@
|
||||
import express from 'express';
|
||||
import passport from 'passport';
|
||||
import jwtDecoder from 'jwt-decode';
|
||||
import { ProfileInfo } from '../providers/types';
|
||||
import { ProfileInfo, RedirectInfo } from '../../providers/types';
|
||||
|
||||
export type PassportDoneCallback<Res, Private = never> = (
|
||||
err?: Error,
|
||||
@@ -64,17 +64,6 @@ export const makeProfileInfo = (
|
||||
};
|
||||
};
|
||||
|
||||
export type RedirectInfo = {
|
||||
/**
|
||||
* URL to redirect to
|
||||
*/
|
||||
url: string;
|
||||
/**
|
||||
* Status code to use for the redirect
|
||||
*/
|
||||
status?: number;
|
||||
};
|
||||
|
||||
export const executeRedirectStrategy = async (
|
||||
req: express.Request,
|
||||
providerStrategy: passport.Strategy,
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2020 Spotify AB
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export {
|
||||
executeFetchUserProfileStrategy,
|
||||
executeFrameHandlerStrategy,
|
||||
executeRedirectStrategy,
|
||||
executeRefreshTokenStrategy,
|
||||
makeProfileInfo,
|
||||
} from './PassportStrategyHelper';
|
||||
export type { PassportDoneCallback } from './PassportStrategyHelper';
|
||||
@@ -32,9 +32,8 @@ import {
|
||||
executeRefreshTokenStrategy,
|
||||
makeProfileInfo,
|
||||
PassportDoneCallback,
|
||||
RedirectInfo,
|
||||
} from '../../lib/PassportStrategyHelper';
|
||||
import { AuthProviderConfig } from '../types';
|
||||
} from '../../lib/passport';
|
||||
import { AuthProviderConfig, RedirectInfo } from '../types';
|
||||
import { Config } from '@backstage/config';
|
||||
|
||||
type PrivateInfo = {
|
||||
|
||||
@@ -21,9 +21,8 @@ import {
|
||||
executeRedirectStrategy,
|
||||
makeProfileInfo,
|
||||
PassportDoneCallback,
|
||||
RedirectInfo,
|
||||
} from '../../lib/PassportStrategyHelper';
|
||||
import { AuthProviderConfig } from '../types';
|
||||
} from '../../lib/passport';
|
||||
import { AuthProviderConfig, RedirectInfo } from '../types';
|
||||
import {
|
||||
OAuthProvider,
|
||||
OAuthProviderOptions,
|
||||
|
||||
@@ -21,9 +21,8 @@ import {
|
||||
executeRedirectStrategy,
|
||||
makeProfileInfo,
|
||||
PassportDoneCallback,
|
||||
RedirectInfo,
|
||||
} from '../../lib/PassportStrategyHelper';
|
||||
import { AuthProviderConfig } from '../types';
|
||||
} from '../../lib/passport';
|
||||
import { AuthProviderConfig, RedirectInfo } from '../types';
|
||||
import {
|
||||
OAuthProvider,
|
||||
OAuthProviderOptions,
|
||||
|
||||
@@ -23,9 +23,8 @@ import {
|
||||
makeProfileInfo,
|
||||
executeFetchUserProfileStrategy,
|
||||
PassportDoneCallback,
|
||||
RedirectInfo,
|
||||
} from '../../lib/PassportStrategyHelper';
|
||||
import { AuthProviderConfig } from '../types';
|
||||
} from '../../lib/passport';
|
||||
import { AuthProviderConfig, RedirectInfo } from '../types';
|
||||
import {
|
||||
OAuthProvider,
|
||||
OAuthProviderHandlers,
|
||||
|
||||
@@ -25,10 +25,9 @@ import {
|
||||
makeProfileInfo,
|
||||
executeFetchUserProfileStrategy,
|
||||
PassportDoneCallback,
|
||||
RedirectInfo,
|
||||
} from '../../lib/PassportStrategyHelper';
|
||||
} from '../../lib/passport';
|
||||
|
||||
import { AuthProviderConfig } from '../types';
|
||||
import { AuthProviderConfig, RedirectInfo } from '../types';
|
||||
|
||||
import {
|
||||
OAuthProvider,
|
||||
|
||||
@@ -32,9 +32,8 @@ import {
|
||||
executeRefreshTokenStrategy,
|
||||
makeProfileInfo,
|
||||
PassportDoneCallback,
|
||||
RedirectInfo,
|
||||
} from '../../lib/PassportStrategyHelper';
|
||||
import { AuthProviderConfig } from '../types';
|
||||
} from '../../lib/passport';
|
||||
import { AuthProviderConfig, RedirectInfo } from '../types';
|
||||
import { Config } from '@backstage/config';
|
||||
|
||||
type PrivateInfo = {
|
||||
|
||||
@@ -29,9 +29,8 @@ import {
|
||||
makeProfileInfo,
|
||||
executeFetchUserProfileStrategy,
|
||||
PassportDoneCallback,
|
||||
RedirectInfo,
|
||||
} from '../../lib/PassportStrategyHelper';
|
||||
import { AuthProviderConfig } from '../types';
|
||||
} from '../../lib/passport';
|
||||
import { AuthProviderConfig, RedirectInfo } from '../types';
|
||||
import { Logger } from 'winston';
|
||||
import { StateStore } from 'passport-oauth2';
|
||||
import { TokenIssuer } from '../../identity';
|
||||
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
executeFrameHandlerStrategy,
|
||||
executeRedirectStrategy,
|
||||
PassportDoneCallback,
|
||||
} from '../../lib/PassportStrategyHelper';
|
||||
} from '../../lib/passport';
|
||||
import {
|
||||
AuthProviderConfig,
|
||||
AuthProviderRouteHandlers,
|
||||
|
||||
@@ -32,6 +32,17 @@ export type AuthProviderConfig = {
|
||||
appUrl: string;
|
||||
};
|
||||
|
||||
export type RedirectInfo = {
|
||||
/**
|
||||
* URL to redirect to
|
||||
*/
|
||||
url: string;
|
||||
/**
|
||||
* Status code to use for the redirect
|
||||
*/
|
||||
status?: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* Any Auth provider needs to implement this interface which handles the routes in the
|
||||
* auth backend. Any auth API requests from the frontend reaches these methods.
|
||||
|
||||
Reference in New Issue
Block a user