Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: msal upgrade #883

Merged
merged 39 commits into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
3bc16fc
replace msal with azure/msal-browser
thewahome Mar 5, 2021
d434316
implement the authentication module
thewahome Mar 5, 2021
c9e0117
add session id to maintain session from try-it experience
thewahome Mar 8, 2021
735b038
remove variable introductions for return statements
thewahome Mar 9, 2021
26cbb09
add try-catch block when getting the token
thewahome Mar 9, 2021
dffb722
change file to util
thewahome Mar 9, 2021
ca13997
move auth files to auth folder
thewahome Mar 9, 2021
522bca6
Update src/app/services/graph-client/auth/custom-authentication-provi…
thewahome Mar 9, 2021
8e013d1
create authmodule as singleton class
thewahome Mar 9, 2021
bd5da7c
Merge branch 'feature/msal-upgrade' of https://github.com/microsoftgr…
thewahome Mar 9, 2021
80983a9
Use already exported instance of msal application
thewahome Mar 9, 2021
d765db6
move msal-service to auth module folder
thewahome Mar 9, 2021
ba89fe8
move msal-service functions to authentication module file
thewahome Mar 10, 2021
d8a47ef
rename file to AuthenticationWrapper
thewahome Mar 10, 2021
5845455
move auth to authentication module folder
thewahome Mar 10, 2021
6c6938b
move graph authentication provider closer to source
thewahome Mar 10, 2021
cc6765e
create authentication wrapper interface
thewahome Mar 10, 2021
68a210a
store home account id to identify logged in account
thewahome Mar 11, 2021
178a841
change key to guid
thewahome Mar 12, 2021
b6eee86
Update src/modules/authentication/AuthenticationWrapper.ts
thewahome Mar 12, 2021
51b96bf
trigger log in if there is no homeId
thewahome Mar 12, 2021
cbf7ff2
Merge branch 'feature/msal-upgrade' of https://github.com/microsoftgr…
thewahome Mar 12, 2021
b230e4d
clear cache to support logoutPopUp
thewahome Mar 12, 2021
d0f7ae0
add a homeaccountId to the filter
thewahome Mar 15, 2021
1f2d81a
Experiment: add environment variable
thewahome Mar 16, 2021
f844bd3
show error when consent fails
thewahome Apr 6, 2021
602958b
Merge branch 'dev' into feature/msal-upgrade
thewahome Apr 6, 2021
c8dab2b
fix lock file
thewahome Apr 6, 2021
e14ecda
fix failing msal crypto related test
thewahome Apr 7, 2021
c0a0fe4
reference correct local storage key in telemetry
thewahome Apr 7, 2021
f02ac9e
log in with interaction when consenting to new permissions
thewahome Apr 8, 2021
c209706
Merge branch 'dev' into feature/msal-upgrade
thewahome Apr 14, 2021
886d42c
bypass selecting the account when consenting to scopes
thewahome Apr 14, 2021
f269d2d
add flag to ensure we are not stuck in infinite loop
thewahome Apr 14, 2021
5884ca8
rearrange statements in function
thewahome Apr 15, 2021
57a32f8
defend against null accounts
thewahome Apr 15, 2021
467ad75
change function to show expected meaning
thewahome Apr 19, 2021
9a26ad4
specify return types and directly use constant
thewahome Apr 20, 2021
eef484b
change isConsentFlow variable name
thewahome Apr 22, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
with:
submodules: true
- name: Build And Deploy
env:
REACT_APP_CLIENT_ID: ${{ secrets.REACT_APP_CLIENT_ID }}
id: builddeploy
uses: Azure/static-web-apps-deploy@v0.0.1-preview
with:
Expand Down
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ module.exports = {
"<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}",
"<rootDir>/src/**/?(*.)(spec|test).{js,jsx,ts,tsx}"
],
globals: {
crypto: require("crypto")
},
testEnvironment: "jsdom",
testURL: "http://localhost",
transform: {
Expand Down
42 changes: 28 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "4.4.2",
"private": true,
"dependencies": {
"@azure/msal-browser": "2.12.0",
"@babel/core": "7.12.13",
"@babel/eslint-parser": "7.12.13",
"@microsoft/applicationinsights-react-js": "2.3.1",
Expand Down Expand Up @@ -48,7 +49,6 @@
"mini-css-extract-plugin": "0.5.0",
"monaco-editor": "0.15.6",
"monaco-editor-webpack-plugin": "1.7.0",
"msal": "1.2.1",
"node-sass": "4.14.1",
"office-ui-fabric-react": "7.121.2",
"optimize-css-assets-webpack-plugin": "5.0.1",
Expand Down Expand Up @@ -124,6 +124,7 @@
"babel-jest": "26.6.3",
"braces": "2.3.1",
"chromedriver": "^88.0.0",
"crypto": "1.0.1",
"enzyme": "3.9.0",
"enzyme-adapter-react-16": "1.9.1",
"eslint": "5.16.0",
Expand Down
6 changes: 3 additions & 3 deletions src/app/services/actions/auth-action-creators.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { authenticationWrapper } from '../../../modules/authentication';
import { IAction } from '../../../types/action';
import { Mode } from '../../../types/enums';
import { logOut, logOutPopUp } from '../graph-client/msal-service';
import { GET_AUTH_TOKEN_SUCCESS, GET_CONSENTED_SCOPES_SUCCESS, LOGOUT_SUCCESS } from '../redux-constants';

export function getAuthTokenSuccess(response: boolean): any {
Expand All @@ -27,9 +27,9 @@ export function signOut() {
return (dispatch: Function, getState: Function) => {
const { graphExplorerMode } = getState();
if (graphExplorerMode === Mode.Complete) {
logOut();
authenticationWrapper.logOut();
} else {
logOutPopUp();
authenticationWrapper.logOutPopUp();
}
dispatch(signOutSuccess(false));
};
Expand Down
24 changes: 19 additions & 5 deletions src/app/services/actions/permissions-action-creator.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { SeverityLevel } from '@microsoft/applicationinsights-web';
import { MessageBarType } from 'office-ui-fabric-react';

import { geLocale } from '../../../appLocale';
import { authenticationWrapper } from '../../../modules/authentication';
import { componentNames, errorTypes, telemetry } from '../../../telemetry';
import { IAction } from '../../../types/action';
import { IQuery } from '../../../types/query-runner';
import { IRequestOptions } from '../../../types/request';
import { sanitizeQueryUrl } from '../../utils/query-url-sanitization';
import { parseSampleUrl } from '../../utils/sample-url-generation';
import { acquireNewAccessToken } from '../graph-client/msal-service';
import { translateMessage } from '../../utils/translate-messages';
import { FETCH_SCOPES_ERROR, FETCH_SCOPES_PENDING, FETCH_SCOPES_SUCCESS } from '../redux-constants';
import { getAuthTokenSuccess, getConsentedScopesSuccess } from './auth-action-creators';
import { setQueryResponseStatus } from './query-status-action-creator';

export function fetchScopesSuccess(response: object): IAction {
return {
Expand Down Expand Up @@ -88,10 +92,20 @@ export function fetchScopes(query?: IQuery): Function {

export function consentToScopes(scopes: string[]): Function {
return async (dispatch: Function) => {
const authResponse = await acquireNewAccessToken(scopes);
if (authResponse && authResponse.accessToken) {
dispatch(getAuthTokenSuccess(true));
dispatch(getConsentedScopesSuccess(authResponse.scopes));
try {
const authResponse = await authenticationWrapper.consentToScopes(scopes);
if (authResponse && authResponse.accessToken) {
dispatch(getAuthTokenSuccess(true));
dispatch(getConsentedScopesSuccess(authResponse.scopes));
}
} catch (error) {
const { errorCode } = error;
dispatch(setQueryResponseStatus({
statusText: translateMessage('Scope consent failed'),
status: errorCode,
ok: false,
messageType: MessageBarType.error
}))
}
};
}
3 changes: 1 addition & 2 deletions src/app/services/actions/query-action-creator-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { IAction } from '../../../types/action';
import { ContentType } from '../../../types/enums';
import { IQuery } from '../../../types/query-runner';
import { IRequestOptions } from '../../../types/request';
import { GraphClient } from '../graph-client';
import { authProvider } from '../graph-client/msal-agent';
import { authProvider, GraphClient } from '../graph-client';
import { DEFAULT_USER_SCOPES, GRAPH_API_SANDBOX_URL } from '../graph-constants';
import { QUERY_GRAPH_SUCCESS } from '../redux-constants';
import { queryRunningStatus } from './query-loading-action-creators';
Expand Down
17 changes: 17 additions & 0 deletions src/app/services/graph-client/GraphAuthenticationProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { AuthenticationProvider } from '@microsoft/microsoft-graph-client';

import { authenticationWrapper } from '../../../modules/authentication';

export class GraphAuthenticationProvider implements AuthenticationProvider {
/**
* getAccessToken
*/
public async getAccessToken(): Promise<string> {
try {
const authResult = await authenticationWrapper.getToken();
return authResult.accessToken;
} catch (error) {
throw error;
}
}
}
2 changes: 1 addition & 1 deletion src/app/services/graph-client/graph-client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Client } from '@microsoft/microsoft-graph-client';
import 'isomorphic-fetch';
import { authProvider } from './msal-agent';
import { authProvider } from './';

export class GraphClient {
private static client: Client;
Expand Down
3 changes: 3 additions & 0 deletions src/app/services/graph-client/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
import { GraphAuthenticationProvider } from './GraphAuthenticationProvider';

export { GraphClient } from './graph-client';
export const authProvider = new GraphAuthenticationProvider();
32 changes: 0 additions & 32 deletions src/app/services/graph-client/msal-agent.ts

This file was deleted.

Loading