generated from magda-io/magda-auth-google
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createAuthPluginRouter.ts
45 lines (38 loc) · 1.69 KB
/
createAuthPluginRouter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import express, { Router } from "express";
import { Authenticator } from "passport";
import { default as ApiClient } from "@magda/auth-api-client";
import { AuthPluginConfig } from "@magda/authentication-plugin-sdk";
export interface AuthPluginRouterOptions {
authorizationApi: ApiClient;
passport: Authenticator;
clientId: string; // clientId that might be required by your IDP provider
clientSecret: string; // clientSecret that might be required by your IDP provider
externalUrl: string;
authPluginRedirectUrl: string;
authPluginConfig: AuthPluginConfig;
}
export default function createAuthPluginRouter(
options: AuthPluginRouterOptions
): Router {
//const authorizationApi = options.authorizationApi;
//const passport = options.passport;
const clientId = options.clientId;
const clientSecret = options.clientSecret;
//const externalUrl = options.externalUrl;
//const loginBaseUrl = `${externalUrl}/auth/login/plugin`;
/*const resultRedirectionUrl = getAbsoluteUrl(
options.authPluginRedirectUrl,
externalUrl
);*/
if (!clientId) {
throw new Error("Required client id can't be empty!");
}
if (!clientSecret) {
throw new Error("Required client secret can't be empty!");
}
const router: express.Router = express.Router();
// You can use passport to setup http endpoint for your authentication plugin using a `passport strategy`.
// You can find passport.js `strategies` that support different IDPs (identity providers) or authentication servers from [here](http://www.passportjs.org/packages/).
// You can find an example [here](https://github.com/magda-io/magda-auth-google)
return router;
}