-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathSampleAppButtonLaunch.js
51 lines (46 loc) · 1.79 KB
/
SampleAppButtonLaunch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import * as React from 'react';
import { AzureAD, LoginType, AuthenticationState } from 'react-aad-msal';
import { basicReduxStore } from './reduxStore';
import GetAccessTokenButton from './GetAccessTokenButton';
import GetIdTokenButton from './GetIdTokenButton';
// Import the authentication provider which holds the default settings
import { authProvider } from './authProvider';
class SampleAppButtonLaunch extends React.Component {
constructor(props) {
super(props);
// Change the login type to execute in a Popup
const options = authProvider.getProviderOptions();
options.loginType = LoginType.Popup;
authProvider.setProviderOptions(options);
}
render() {
return (
<AzureAD provider={authProvider} reduxStore={basicReduxStore}>
{({ login, logout, authenticationState }) => {
const isInProgress = authenticationState === AuthenticationState.InProgress;
const isAuthenticated = authenticationState === AuthenticationState.Authenticated;
const isUnauthenticated = authenticationState === AuthenticationState.Unauthenticated;
if (isAuthenticated) {
return (
<React.Fragment>
<p>You're logged in!</p>
<button onClick={logout} className="Button">
Logout
</button>
<GetAccessTokenButton provider={authProvider} />
<GetIdTokenButton provider={authProvider} />
</React.Fragment>
);
} else if (isUnauthenticated || isInProgress) {
return (
<button className="Button" onClick={login} disabled={isInProgress}>
Login
</button>
);
}
}}
</AzureAD>
);
}
}
export default SampleAppButtonLaunch;