From cbf1f18b1108bc5e0fe05575c9e60f21587bb91b Mon Sep 17 00:00:00 2001 From: Ryan Slatten Date: Thu, 26 Sep 2024 15:32:34 -0400 Subject: [PATCH] store --- plugins/arcgis/service/src/index.ts | 21 +++++++++++-------- .../projects/main/src/lib/arc.service.ts | 4 ++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/plugins/arcgis/service/src/index.ts b/plugins/arcgis/service/src/index.ts index fac3fdd50..3cf3193fe 100644 --- a/plugins/arcgis/service/src/index.ts +++ b/plugins/arcgis/service/src/index.ts @@ -11,10 +11,11 @@ import { HttpClient } from './HttpClient' import { FeatureServiceResult } from './FeatureServiceResult' import { ArcGISIdentityManager } from "@esri/arcgis-rest-request" -const credentials = { +// TODO: Move configuration to be supplied by the user instead of hardcoded +const oauthCreds = { clientId: 'dzoVuv7Apb5gjJIP', portal: "https://arcgis.geointnext.com/arcgis/sharing/rest", - redirectUri: 'http://localhost:4242/plugins/@ngageoint/mage.arcgis.service/authenticate' + redirectUri: 'http://localhost:4242/plugins/@ngageoint/mage.arcgis.service/oauth/authenticate' } const logPrefix = '[mage.arcgis]' @@ -59,15 +60,17 @@ const arcgisPluginHooks: InitPluginHook = { return { webRoutes: { public: (requestContext: GetAppRequestContext) => { - const routes = express.Router().use(express.json()) - routes.get('/oauth/signin', async (req, res, next) => { - ArcGISIdentityManager.authorize(credentials, res); - }) + const routes = express.Router().use(express.json()); + routes.get('/oauth/sign-in', async (req, res, next) => { + ArcGISIdentityManager.authorize(oauthCreds, res); + }); - routes.post('/oauth/authenticate', async (req, res, next) => { + routes.get('/oauth/authenticate', async (req, res, next) => { const code = req.query.code as string; - ArcGISIdentityManager.exchangeAuthorizationCode(credentials, code) + ArcGISIdentityManager.exchangeAuthorizationCode(oauthCreds, code) .then((identityManager: ArcGISIdentityManager) => { + + identityManager.getUsername().then((username: string) => { console.info('logged in user', username) res.status(200).json({ username }) @@ -76,7 +79,7 @@ const arcgisPluginHooks: InitPluginHook = { console.error(error) next(); }); - }) + }); return routes }, diff --git a/plugins/arcgis/web-app/projects/main/src/lib/arc.service.ts b/plugins/arcgis/web-app/projects/main/src/lib/arc.service.ts index 1edb03965..f940c2738 100644 --- a/plugins/arcgis/web-app/projects/main/src/lib/arc.service.ts +++ b/plugins/arcgis/web-app/projects/main/src/lib/arc.service.ts @@ -33,7 +33,7 @@ export class ArcService { authenticate(): Observable { let subject = new Subject(); - const url = `${baseUrl}/sign-in`; + const url = `${baseUrl}/oauth/sign-in`; const authWindow = window.open(url, "_blank"); function onMessage(event: any) { @@ -45,7 +45,7 @@ export class ArcService { subject.next(event.data) - authWindow?.close(); + // authWindow?.close(); } authWindow?.addEventListener('message', onMessage, false);