diff --git a/dictation_client/package-lock.json b/dictation_client/package-lock.json index 9283e4d..0363f53 100644 --- a/dictation_client/package-lock.json +++ b/dictation_client/package-lock.json @@ -8,6 +8,8 @@ "name": "client", "version": "0.1.0", "dependencies": { + "@azure/msal-browser": "^2.33.0", + "@azure/msal-react": "^1.5.3", "@reduxjs/toolkit": "^1.8.3", "@testing-library/jest-dom": "^5.16.4", "@testing-library/react": "^13.3.0", @@ -77,6 +79,37 @@ "node": ">=6.0.0" } }, + "node_modules/@azure/msal-browser": { + "version": "2.33.0", + "resolved": "https://registry.npmjs.org/@azure/msal-browser/-/msal-browser-2.33.0.tgz", + "integrity": "sha512-c7CVh1tfUfxiWkEIhoIb11hL4PGo4hz0M+gMy34ATagAKdLK7qyEu/5AXJWAf5lz5eE+vQhm7+LKiuETrcXXGw==", + "dependencies": { + "@azure/msal-common": "^10.0.0" + }, + "engines": { + "node": ">=0.8.0" + } + }, + "node_modules/@azure/msal-common": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/@azure/msal-common/-/msal-common-10.0.0.tgz", + "integrity": "sha512-/LghpT93jsZLy55QzTsRZWMx6R1Mjc1Aktwps8sKSGE3WbrGwbSsh2uhDlpl6FMcKChYjJ0ochThWwwOodrQNg==", + "engines": { + "node": ">=0.8.0" + } + }, + "node_modules/@azure/msal-react": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/@azure/msal-react/-/msal-react-1.5.3.tgz", + "integrity": "sha512-PIbksHzNDzEA8iV9BGiKTdxNZVryvJ4CZ/sFhuqX87I5xbCbcxF/oz6iv1qWqtHAeovUigARBZPw7lQOUVsQmg==", + "engines": { + "node": ">=10" + }, + "peerDependencies": { + "@azure/msal-browser": "^2.33.0", + "react": "^16.8.0 || ^17 || ^18" + } + }, "node_modules/@babel/code-frame": { "version": "7.18.6", "license": "MIT", @@ -6188,6 +6221,25 @@ "@jridgewell/trace-mapping": "^0.3.9" } }, + "@azure/msal-browser": { + "version": "2.33.0", + "resolved": "https://registry.npmjs.org/@azure/msal-browser/-/msal-browser-2.33.0.tgz", + "integrity": "sha512-c7CVh1tfUfxiWkEIhoIb11hL4PGo4hz0M+gMy34ATagAKdLK7qyEu/5AXJWAf5lz5eE+vQhm7+LKiuETrcXXGw==", + "requires": { + "@azure/msal-common": "^10.0.0" + } + }, + "@azure/msal-common": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/@azure/msal-common/-/msal-common-10.0.0.tgz", + "integrity": "sha512-/LghpT93jsZLy55QzTsRZWMx6R1Mjc1Aktwps8sKSGE3WbrGwbSsh2uhDlpl6FMcKChYjJ0ochThWwwOodrQNg==" + }, + "@azure/msal-react": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/@azure/msal-react/-/msal-react-1.5.3.tgz", + "integrity": "sha512-PIbksHzNDzEA8iV9BGiKTdxNZVryvJ4CZ/sFhuqX87I5xbCbcxF/oz6iv1qWqtHAeovUigARBZPw7lQOUVsQmg==", + "requires": {} + }, "@babel/code-frame": { "version": "7.18.6", "requires": { diff --git a/dictation_client/package.json b/dictation_client/package.json index 1f813fd..aa8636a 100644 --- a/dictation_client/package.json +++ b/dictation_client/package.json @@ -13,6 +13,8 @@ "lint:fix": "npm run lint -- --fix" }, "dependencies": { + "@azure/msal-browser": "^2.33.0", + "@azure/msal-react": "^1.5.3", "@reduxjs/toolkit": "^1.8.3", "@testing-library/jest-dom": "^5.16.4", "@testing-library/react": "^13.3.0", diff --git a/dictation_client/src/App.tsx b/dictation_client/src/App.tsx index 3a5790c..fe311e6 100644 --- a/dictation_client/src/App.tsx +++ b/dictation_client/src/App.tsx @@ -1,16 +1,22 @@ import AppRouter from "AppRouter"; -import { useEffect } from "react"; -import { useDispatch, useSelector } from "react-redux"; import { BrowserRouter } from "react-router-dom"; import { GlobalStyle } from "styles/GlobalStyle"; +import { PublicClientApplication } from "@azure/msal-browser"; +import { MsalProvider } from "@azure/msal-react"; +import { msalConfig } from "common/auth/msalConfig"; -const App = (): JSX.Element => ( - <> - - - - - -); +const App = (): JSX.Element => { + const pca = new PublicClientApplication(msalConfig); + return ( + <> + + + + + + + + ); +}; export default App; diff --git a/dictation_client/src/AppRouter.tsx b/dictation_client/src/AppRouter.tsx index ab953d5..8cc88dc 100644 --- a/dictation_client/src/AppRouter.tsx +++ b/dictation_client/src/AppRouter.tsx @@ -1,11 +1,15 @@ import { Route, Routes } from "react-router-dom"; import styled from "styled-components"; +import TopPage from "pages/TopPage"; +import LoginPage from "pages/LoginPage"; import SamplePage from "pages/SamplePage"; const AppRouter: React.FC = () => ( - } /> + } /> + } /> + } /> ); diff --git a/dictation_client/src/common/auth/msalConfig.ts b/dictation_client/src/common/auth/msalConfig.ts new file mode 100644 index 0000000..3dbc362 --- /dev/null +++ b/dictation_client/src/common/auth/msalConfig.ts @@ -0,0 +1,17 @@ +import { Configuration, RedirectRequest } from "@azure/msal-browser"; + +export const msalConfig: Configuration = { + auth: { + clientId: "5eb34cba-84b6-46f9-a0ea-bc5c41157d63", + authority: + "https://adb2codmsdev.b2clogin.com/adb2codmsdev.onmicrosoft.com/b2c_1_signin_dev", + knownAuthorities: ["adb2codmsdev.b2clogin.com"], + redirectUri: `${globalThis.location.origin}/login`, + postLogoutRedirectUri: "/", + navigateToLoginRequestUrl: false, + }, +}; + +export const loginRequest: RedirectRequest = { + scopes: ["openid", "offline_access"], +}; diff --git a/dictation_client/src/pages/LoginPage/index.tsx b/dictation_client/src/pages/LoginPage/index.tsx new file mode 100644 index 0000000..2b78f82 --- /dev/null +++ b/dictation_client/src/pages/LoginPage/index.tsx @@ -0,0 +1,28 @@ +import { SilentRequest } from "@azure/msal-browser"; +import { useMsal } from "@azure/msal-react"; +import React, { useState } from "react"; + +const LoginPage: React.FC = () => { + const { accounts, instance } = useMsal(); + const [idToken, setIdToken] = useState(null); + + const request: SilentRequest = { + scopes: ["openid"], + account: accounts[0], + }; + // TODO store側でこの処理を行うべきなので、Task1361で移植する + instance.acquireTokenSilent(request).then((response) => { + setIdToken(response.idToken); + }); + return ( + <> +
{idToken}
+
+ + + ); +}; + +export default LoginPage; diff --git a/dictation_client/src/pages/SamplePage/index.tsx b/dictation_client/src/pages/SamplePage/index.tsx index 0721e10..ef8c383 100644 --- a/dictation_client/src/pages/SamplePage/index.tsx +++ b/dictation_client/src/pages/SamplePage/index.tsx @@ -2,7 +2,7 @@ import React from "react"; const SamplePage: React.FC = () => (
- hello whorld! + hello world!
Dictation App Service Site
diff --git a/dictation_client/src/pages/TopPage/index.tsx b/dictation_client/src/pages/TopPage/index.tsx new file mode 100644 index 0000000..d6440c0 --- /dev/null +++ b/dictation_client/src/pages/TopPage/index.tsx @@ -0,0 +1,20 @@ +import React from "react"; +import { useMsal } from "@azure/msal-react"; +import { loginRequest } from "common/auth/msalConfig"; + +const TopPage: React.FC = () => { + const { instance } = useMsal(); + + return ( +
+ +
+ ); +}; + +export default TopPage;