@@ -29,51 +29,85 @@ import SampleAppButtonLaunch from './SampleAppButtonLaunch';
29
29
import SampleAppRedirectOnLaunch from './SampleAppRedirectOnLaunch' ;
30
30
31
31
class App extends Component {
32
-
32
+
33
33
constructor ( props ) {
34
34
super ( props ) ;
35
-
35
+
36
36
this . state = {
37
- userInfo : null
37
+ userInfo : null ,
38
+ sampleType : null
38
39
} ;
39
40
}
40
41
42
+ componentWillMount = ( ) => {
43
+ if ( sessionStorage . getItem ( 'sampleType' ) ) {
44
+ this . setState ( { sampleType : sessionStorage . getItem ( 'sampleType' ) } ) ;
45
+ }
46
+ }
47
+
41
48
userInfoCallback = ( userInfo ) => {
42
- this . setState ( { userInfo} ) ;
49
+ this . setState ( { userInfo } ) ;
50
+ }
51
+
52
+ handleClick = ( sampleType ) => {
53
+ this . setState ( { sampleType } ) ;
54
+ sessionStorage . setItem ( 'sampleType' , sampleType ) ;
43
55
}
44
56
45
57
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
+
46
94
return (
47
95
< div className = "App" >
48
96
< 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 >
50
98
</ header >
99
+ < br /> < br />
100
+ { sampleButtons }
51
101
< 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 }
69
103
< div className = "SampleBox" >
70
104
< h2 className = "SampleHeader" > Authenticated Values</ h2 >
71
105
< 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 > }
77
111
</ div >
78
112
</ div >
79
113
</ div >
0 commit comments