@@ -29,51 +29,85 @@ import SampleAppButtonLaunch from './SampleAppButtonLaunch';
2929import SampleAppRedirectOnLaunch from './SampleAppRedirectOnLaunch' ;
3030
3131class App extends Component {
32-
32+
3333 constructor ( props ) {
3434 super ( props ) ;
35-
35+
3636 this . state = {
37- userInfo : null
37+ userInfo : null ,
38+ sampleType : null
3839 } ;
3940 }
4041
42+ componentWillMount = ( ) => {
43+ if ( sessionStorage . getItem ( 'sampleType' ) ) {
44+ this . setState ( { sampleType : sessionStorage . getItem ( 'sampleType' ) } ) ;
45+ }
46+ }
47+
4148 userInfoCallback = ( userInfo ) => {
42- this . setState ( { userInfo} ) ;
49+ this . setState ( { userInfo } ) ;
50+ }
51+
52+ handleClick = ( sampleType ) => {
53+ this . setState ( { sampleType } ) ;
54+ sessionStorage . setItem ( 'sampleType' , sampleType ) ;
4355 }
4456
4557 render ( ) {
58+ let sampleBox ;
59+ let sampleButtons ;
60+
61+ if ( this . state . sampleType === "popup" ) {
62+
63+ sampleBox =
64+ < div className = "SampleBox" >
65+ < h2 className = "SampleHeader" > Button Login</ h2 >
66+ < p > This example will launch a popup dialog to allow for authentication
67+ with Azure Active Directory</ p >
68+ < SampleAppButtonLaunch userInfoCallback = { this . userInfoCallback } />
69+ </ div >
70+
71+ } else if ( this . state . sampleType === "redirect" ) {
72+
73+ sampleBox =
74+ < div className = "SampleBox" >
75+ < h2 className = "SampleHeader" > Automatic Redirect</ h2 >
76+ < p > This example shows how you can use the AzureAD component to redirect
77+ the login screen automatically on page load. Click the checkbox below
78+ to enable the redirect and refresh your browser window.
79+ </ p >
80+ < SampleAppRedirectOnLaunch userInfoCallback = { this . userInfoCallback } userInfo = { this . state . userInfo } />
81+ </ div >
82+
83+ }
84+
85+ if ( ! this . state . userInfo ) {
86+ sampleButtons =
87+ < div >
88+ < button onClick = { ( ) => this . handleClick ( "popup" ) } className = "Button" > Popup Sample</ button >
89+ { " " }
90+ < button onClick = { ( ) => this . handleClick ( "redirect" ) } className = "Button" > Redirect Sample</ button >
91+ </ div >
92+ }
93+
4694 return (
4795 < div className = "App" >
4896 < header className = "App-header" >
49- < h1 className = "App-title" > Welcome to react-aad-msal-samples </ h1 >
97+ < h1 className = "App-title" > Welcome to the react-aad-msal sample </ h1 >
5098 </ header >
99+ < br /> < br />
100+ { sampleButtons }
51101 < div className = "SampleContainer" >
52- { /* TODO: Only one sample is supported right now,
53- Please uncomment to try the different methods. */ }
54-
55- < div className = "SampleBox" >
56- < h2 className = "SampleHeader" > Button Login</ h2 >
57- < p > This example will launch a popup dialog to allow for authentication
58- with Azure Active Directory</ p >
59- < SampleAppButtonLaunch userInfoCallback = { this . userInfoCallback } />
60- </ div >
61- { /* <div className="SampleBox">
62- <h2 className="SampleHeader">Automatic Redirect</h2>
63- <p>This example shows how you can use the AzureAD component to redirect
64- the login screen automatically on page load. Click the checkbox below
65- to enable the redirect and refresh your browser window.
66- </p>
67- <SampleAppRedirectOnLaunch userInfoCallback={this.userInfoCallback} userInfo={this.state.userInfo}/>
68- </div> */ }
102+ { sampleBox }
69103 < div className = "SampleBox" >
70104 < h2 className = "SampleHeader" > Authenticated Values</ h2 >
71105 < p > When logged in, this box will show your tokens and user info</ p >
72- { this . state . userInfo && < div style = { { wordWrap : "break-word" } } >
73- < span style = { { fontWeight : "bold" } } > User Information:</ span > < br />
74- < span style = { { fontWeight : "bold" } } > ID Token:</ span > { this . state . userInfo . jwtIdToken } < br />
75- < span style = { { fontWeight : "bold" } } > Access Token:</ span > { this . state . userInfo . jwtAccessToken } < br />
76- < span style = { { fontWeight : "bold" } } > Username:</ span > { this . state . userInfo . user . name } </ div > }
106+ { this . state . userInfo && < div style = { { wordWrap : "break-word" } } >
107+ < span style = { { fontWeight : "bold" } } > User Information:</ span > < br />
108+ < span style = { { fontWeight : "bold" } } > ID Token:</ span > { this . state . userInfo . jwtIdToken } < br />
109+ < span style = { { fontWeight : "bold" } } > Access Token:</ span > { this . state . userInfo . jwtAccessToken } < br />
110+ < span style = { { fontWeight : "bold" } } > Username:</ span > { this . state . userInfo . user . name } </ div > }
77111 </ div >
78112 </ div >
79113 </ div >
0 commit comments