Skip to content

Commit

Permalink
store
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanslatten committed Sep 26, 2024
1 parent edaca84 commit cbf1f18
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
21 changes: 12 additions & 9 deletions plugins/arcgis/service/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]'
Expand Down Expand Up @@ -59,15 +60,17 @@ const arcgisPluginHooks: InitPluginHook<typeof InjectedServices> = {
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 })
Expand All @@ -76,7 +79,7 @@ const arcgisPluginHooks: InitPluginHook<typeof InjectedServices> = {
console.error(error)
next();
});
})
});

return routes
},
Expand Down
4 changes: 2 additions & 2 deletions plugins/arcgis/web-app/projects/main/src/lib/arc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class ArcService {
authenticate(): Observable<any> {
let subject = new Subject<any>();

const url = `${baseUrl}/sign-in`;
const url = `${baseUrl}/oauth/sign-in`;
const authWindow = window.open(url, "_blank");

function onMessage(event: any) {
Expand All @@ -45,7 +45,7 @@ export class ArcService {

subject.next(event.data)

authWindow?.close();
// authWindow?.close();
}

authWindow?.addEventListener('message', onMessage, false);
Expand Down

0 comments on commit cbf1f18

Please sign in to comment.