@@ -8,7 +8,7 @@ import { ArcGISPluginConfig } from './ArcGISPluginConfig'
88import { AuthType } from './ArcGISConfig'
99import { ObservationProcessor } from './ObservationProcessor'
1010import { ArcGISIdentityManager , request } from "@esri/arcgis-rest-request"
11- import { FeatureServiceConfig } from './ArcGISConfig'
11+ import { FeatureServiceConfig , OAuthAuthConfig } from './ArcGISConfig'
1212import { URL } from "node:url"
1313import express from 'express'
1414import { getIdentityManager , getPortalUrl } from './ArcGISIdentityManagerFactory'
@@ -37,6 +37,19 @@ const InjectedServices = {
3737
3838const pluginWebRoute = "plugins/@ngageoint/mage.arcgis.service"
3939
40+ const sanitizeFeatureService = ( config : FeatureServiceConfig , type : AuthType ) : FeatureServiceConfig => {
41+ if ( type === AuthType . OAuth ) {
42+ const newAuth = Object . assign ( { } , config . auth ) as OAuthAuthConfig ;
43+ delete newAuth . refreshToken ;
44+ delete newAuth . refreshTokenExpires ;
45+ return {
46+ ...config ,
47+ auth : newAuth
48+ }
49+ }
50+ return config ;
51+ }
52+
4053/**
4154 * The MAGE ArcGIS Plugin finds new MAGE observations and if configured to send the observations
4255 * to an ArcGIS server, it will then transform the observation to an ArcGIS feature and
@@ -74,7 +87,7 @@ const arcgisPluginHooks: InitPluginHook<typeof InjectedServices> = {
7487 return res . status ( 404 ) . send ( 'clientId is required' )
7588 }
7689
77- const config = await processor . safeGetConfig ( true )
90+ const config = await processor . safeGetConfig ( )
7891 ArcGISIdentityManager . authorize ( {
7992 clientId,
8093 portal : getPortalUrl ( url ) ,
@@ -95,7 +108,7 @@ const arcgisPluginHooks: InitPluginHook<typeof InjectedServices> = {
95108 return res . sendStatus ( 500 )
96109 }
97110
98- const config = await processor . safeGetConfig ( true )
111+ const config = await processor . safeGetConfig ( )
99112 const creds = {
100113 clientId : state . clientId ,
101114 redirectUri : `${ config . baseUrl } /${ pluginWebRoute } /oauth/authenticate` ,
@@ -150,6 +163,7 @@ const arcgisPluginHooks: InitPluginHook<typeof InjectedServices> = {
150163 . get ( async ( req , res , next ) => {
151164 console . info ( 'Getting ArcGIS plugin config...' )
152165 const config = await processor . safeGetConfig ( )
166+ config . featureServices = config . featureServices . map ( ( service ) => sanitizeFeatureService ( service , AuthType . OAuth ) ) ;
153167 res . json ( config )
154168 } )
155169 . put ( async ( req , res , next ) => {
@@ -161,7 +175,7 @@ const arcgisPluginHooks: InitPluginHook<typeof InjectedServices> = {
161175 } )
162176
163177 routes . post ( '/featureService/validate' , async ( req , res ) => {
164- const config = await processor . safeGetConfig ( true )
178+ const config = await processor . safeGetConfig ( )
165179 const { url, auth = { } } = req . body
166180 const { token, username, password } = auth
167181 if ( ! URL . canParse ( url ) ) {
@@ -186,17 +200,16 @@ const arcgisPluginHooks: InitPluginHook<typeof InjectedServices> = {
186200 } else {
187201 config . featureServices . push ( service )
188202 }
189- console . log ( 'values patch' )
190203 await processor . patchConfig ( config )
191- return res . send ( processor . sanitizeFeatureService ( service , AuthType . OAuth ) )
204+ return res . send ( sanitizeFeatureService ( service , AuthType . OAuth ) )
192205 } catch ( err ) {
193206 return res . send ( 'Invalid credentials provided to communicate with feature service' ) . status ( 400 )
194207 }
195208 } )
196209
197210 routes . get ( '/featureService/layers' , async ( req , res , next ) => {
198211 const url = req . query . featureServiceUrl as string
199- const config = await processor . safeGetConfig ( true )
212+ const config = await processor . safeGetConfig ( )
200213 const featureService = config . featureServices . find ( featureService => featureService . url === url )
201214 if ( ! featureService ) {
202215 return res . status ( 400 )
0 commit comments