Skip to content

Commit

Permalink
Make workbench service url configurable (microsoft#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
markwaddle authored Sep 30, 2024
1 parent 65411b0 commit f9ee1ae
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 43 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/workbench-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ on:

jobs:
build-pr:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest

steps:
Expand All @@ -41,7 +42,7 @@ jobs:

build-main:
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
environment:
name: production

Expand Down Expand Up @@ -78,7 +79,7 @@ jobs:

deploy:
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
needs: build-main
environment:
name: production
Expand Down
3 changes: 3 additions & 0 deletions workbench-app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ VITE_SEMANTIC_WORKBENCH_CLIENT_ID=22cb77c3-ca98-4a26-b4db-ac4dcecba690
# - Work + School + Personal: 'https://login.microsoftonline.com/common'
#
VITE_SEMANTIC_WORKBENCH_AUTHORITY=https://login.microsoftonline.com/common

# The URL for the Semantic Workbench service.
VITE_SEMANTIC_WORKBENCH_SERVICE_URL=http://localhost:3000
9 changes: 6 additions & 3 deletions workbench-app/src/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export const Constants = {
{
id: 'local',
name: 'Semantic Workbench backend service on localhost or GitHub Codespaces',
url: 'http://localhost:3000',
// Can be overridden by env var VITE_SEMANTIC_WORKBENCH_SERVICE_URL
url: import.meta.env.VITE_SEMANTIC_WORKBENCH_SERVICE_URL || 'http://localhost:3000',
brand: 'light',
},
// {
Expand All @@ -47,13 +48,15 @@ export const Constants = {
// Semantic Workbench GitHub sample app registration
// The same value is set also in AuthSettings in
// "semantic_workbench_service.config.py" in the backend
clientId: '22cb77c3-ca98-4a26-b4db-ac4dcecba690',
// Can be overridden by env var VITE_SEMANTIC_WORKBENCH_CLIENT_ID
clientId: import.meta.env.VITE_SEMANTIC_WORKBENCH_CLIENT_ID || '22cb77c3-ca98-4a26-b4db-ac4dcecba690',

// Specific tenant only: 'https://login.microsoftonline.com/<tenant>/',
// Personal accounts only: 'https://login.microsoftonline.com/consumers',
// Work + School accounts: 'https://login.microsoftonline.com/organizations',
// Work + School + Personal: 'https://login.microsoftonline.com/common'
authority: 'https://login.microsoftonline.com/common',
// Can be overridden by env var VITE_SEMANTIC_WORKBENCH_AUTHORITY
authority: import.meta.env.VITE_SEMANTIC_WORKBENCH_AUTHORITY || 'https://login.microsoftonline.com/common',
},
cache: {
cacheLocation: 'localStorage',
Expand Down
64 changes: 26 additions & 38 deletions workbench-app/src/libs/AuthHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,35 @@ import { Constants } from '../Constants';

const log = debug(Constants.debug.root).extend('auth-helper');

const getMsalConfig = () => {
const envClientId: string | undefined = import.meta.env.VITE_SEMANTIC_WORKBENCH_CLIENT_ID;
const envAuthority: string | undefined = import.meta.env.VITE_SEMANTIC_WORKBENCH_AUTHORITY;
const clientId = envClientId || Constants.msal.auth.clientId;
const authority = envAuthority || Constants.msal.auth.authority;

log(`Using clientId: ${clientId} (from env: ${!!envClientId})`);
log(`Using authority: ${authority} (from env: ${!!envAuthority})`);

return {
auth: {
...Constants.msal.auth,
clientId,
authority,
redirectUri: window.origin,
},
cache: Constants.msal.cache,
system: {
loggerOptions: {
loggerCallback: (level: any, message: any, containsPii: any) => {
if (containsPii) {
const getMsalConfig = () => ({
auth: {
...Constants.msal.auth,
redirectUri: window.origin,
},
cache: Constants.msal.cache,
system: {
loggerOptions: {
loggerCallback: (level: any, message: any, containsPii: any) => {
if (containsPii) {
return;
}
switch (level) {
case LogLevel.Error:
log('error:', message);
return;
}
switch (level) {
case LogLevel.Error:
log('error:', message);
return;
// case LogLevel.Info:
// log('info:', message);
// return;
// case LogLevel.Verbose:
// log('verbose:', message);
// return;
case LogLevel.Warning:
log('warn:', message);
}
},
// case LogLevel.Info:
// log('info:', message);
// return;
// case LogLevel.Verbose:
// log('verbose:', message);
// return;
case LogLevel.Warning:
log('warn:', message);
}
},
},
};
};
},
});

const loginRequest: RedirectRequest = {
scopes: Constants.msal.msGraphScopes,
Expand Down

0 comments on commit f9ee1ae

Please sign in to comment.