|
1 | | -<!DOCTYPE html> |
| 1 | +<!doctype html> |
2 | 2 | <!-- |
3 | 3 | Copyright (c) 2019 Google Inc. |
4 | 4 |
|
|
15 | 15 | limitations under the License. |
16 | 16 | --> |
17 | 17 | <html> |
18 | | -<head> |
19 | | - <meta charset=utf-8 /> |
20 | | - <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
21 | | - <title>Microsoft Sign In Example</title> |
22 | | - |
23 | | - <!-- Material Design Theming --> |
24 | | - <link rel="stylesheet" href="https://code.getmdl.io/1.1.3/material.orange-indigo.min.css"> |
25 | | - <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"> |
26 | | - <script defer src="https://code.getmdl.io/1.1.3/material.min.js"></script> |
27 | | - |
28 | | - <link rel="stylesheet" href="main.css"> |
29 | | - |
30 | | - <!-- Import and configure the Firebase SDK --> |
31 | | - <!-- These scripts are made available when the app is served or deployed on Firebase Hosting --> |
32 | | - <!-- If you do not serve/host your project using Firebase Hosting see https://firebase.google.com/docs/web/setup --> |
33 | | - <script src="/__/firebase/9.22.1/firebase-app-compat.js"></script> |
34 | | - <script src="/__/firebase/9.22.1/firebase-auth-compat.js"></script> |
35 | | - <script src="/__/firebase/init.js"></script> |
36 | | - |
37 | | - <script type="text/javascript"> |
38 | | - |
39 | | - /** |
40 | | - * Function called when clicking the Login/Logout button. |
41 | | - */ |
42 | | - function toggleSignIn() { |
43 | | - if (!firebase.auth().currentUser) { |
44 | | - var provider = new firebase.auth.OAuthProvider('microsoft.com'); |
45 | | - |
46 | | - provider.addScope('User.Read'); |
47 | | - firebase.auth().signInWithPopup(provider).then(function(result) { |
48 | | - // This gives you a Microsoft Access Token. You can use it to access the Microsoft API. |
49 | | - var token = result.credential.accessToken; |
50 | | - // You can also retrieve the OAuth ID token. |
51 | | - var idToken = result.credential.idToken; |
52 | | - // The signed-in user info. |
53 | | - var user = result.user; |
54 | | - document.getElementById('quickstart-oauthtoken').textContent = token; |
55 | | - }).catch(function(error) { |
56 | | - // Handle Errors here. |
57 | | - var errorCode = error.code; |
58 | | - var errorMessage = error.message; |
59 | | - // The email of the user's account used. |
60 | | - var email = error.email; |
61 | | - // The firebase.auth.AuthCredential type that was used. |
62 | | - var credential = error.credential; |
63 | | - if (errorCode === 'auth/account-exists-with-different-credential') { |
64 | | - alert('You have already signed up with a different auth provider for that email.'); |
65 | | - // If you are using multiple auth providers on your app you should handle linking |
66 | | - // the user's accounts here. |
67 | | - } else { |
68 | | - console.error(error); |
69 | | - } |
70 | | - }); |
71 | | - } else { |
72 | | - firebase.auth().signOut(); |
73 | | - } |
74 | | - document.getElementById('quickstart-sign-in').disabled = true; |
75 | | - } |
76 | | - |
77 | | - /** |
78 | | - * initApp handles setting up UI event listeners and registering Firebase auth listeners: |
79 | | - * - firebase.auth().onAuthStateChanged: This listener is called when the user is signed in or |
80 | | - * out, and that is where we update the UI. |
81 | | - */ |
82 | | - function initApp() { |
83 | | - // Listening for auth state changes. |
84 | | - firebase.auth().onAuthStateChanged(function(user) { |
85 | | - if (user) { |
86 | | - // User is signed in. Note that unlike other providers supported by Firebase Auth, Microsoft does |
87 | | - // not provide a profile photo so user.photoURL will be null. However, it can be queried using |
88 | | - // the Microsoft Graph API: https://docs.microsoft.com/en-us/graph/api/profilephoto-get |
89 | | - var displayName = user.displayName; |
90 | | - var email = user.email; |
91 | | - var emailVerified = user.emailVerified; |
92 | | - var isAnonymous = user.isAnonymous; |
93 | | - var uid = user.uid; |
94 | | - var providerData = user.providerData; |
95 | | - document.getElementById('quickstart-sign-in-status').textContent = 'Signed in'; |
96 | | - document.getElementById('quickstart-sign-in').textContent = 'Log out'; |
97 | | - document.getElementById('quickstart-account-details').textContent = JSON.stringify(user, null, ' '); |
98 | | - } else { |
99 | | - // User is signed out. |
100 | | - document.getElementById('quickstart-sign-in-status').textContent = 'Signed out'; |
101 | | - document.getElementById('quickstart-sign-in').textContent = 'Log in with Microsoft'; |
102 | | - document.getElementById('quickstart-account-details').textContent = 'null'; |
103 | | - document.getElementById('quickstart-oauthtoken').textContent = 'null'; |
104 | | - } |
105 | | - document.getElementById('quickstart-sign-in').disabled = false; |
106 | | - }); |
107 | | - |
108 | | - document.getElementById('quickstart-sign-in').addEventListener('click', toggleSignIn, false); |
109 | | - } |
110 | | - |
111 | | - window.onload = function() { |
112 | | - initApp(); |
113 | | - }; |
114 | | - </script> |
115 | | -</head> |
116 | | -<body> |
117 | | -<div class="demo-layout mdl-layout mdl-js-layout mdl-layout--fixed-header"> |
118 | | - |
119 | | - <!-- Header section containing title --> |
120 | | - <header class="mdl-layout__header mdl-color-text--white mdl-color--light-blue-700"> |
121 | | - <div class="mdl-cell mdl-cell--12-col mdl-cell--12-col-tablet mdl-grid"> |
122 | | - <div class="mdl-layout__header-row mdl-cell mdl-cell--12-col mdl-cell--12-col-tablet mdl-cell--8-col-desktop"> |
123 | | - <a href="/"><h3>Firebase Authentication</h3></a> |
124 | | - </div> |
125 | | - </div> |
126 | | - </header> |
127 | | - |
128 | | - <main class="mdl-layout__content mdl-color--grey-100"> |
129 | | - <div class="mdl-cell mdl-cell--12-col mdl-cell--12-col-tablet mdl-grid"> |
130 | | - |
131 | | - <!-- Container for the demo --> |
132 | | - <div class="mdl-card mdl-shadow--2dp mdl-cell mdl-cell--12-col mdl-cell--12-col-tablet mdl-cell--12-col-desktop"> |
133 | | - <div class="mdl-card__title mdl-color--light-blue-600 mdl-color-text--white"> |
134 | | - <h2 class="mdl-card__title-text">Microsoft Authentication with Popup</h2> |
| 18 | + <head> |
| 19 | + <meta charset="utf-8" /> |
| 20 | + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 21 | + <title>Microsoft Sign In Example</title> |
| 22 | + |
| 23 | + <!-- Material Design Theming --> |
| 24 | + <link |
| 25 | + rel="stylesheet" |
| 26 | + href="https://code.getmdl.io/1.1.3/material.orange-indigo.min.css" |
| 27 | + /> |
| 28 | + <link |
| 29 | + rel="stylesheet" |
| 30 | + href="https://fonts.googleapis.com/icon?family=Material+Icons" |
| 31 | + /> |
| 32 | + <script defer src="https://code.getmdl.io/1.1.3/material.min.js"></script> |
| 33 | + |
| 34 | + <link rel="stylesheet" href="main.css" /> |
| 35 | + </head> |
| 36 | + <body> |
| 37 | + <div class="demo-layout mdl-layout mdl-js-layout mdl-layout--fixed-header"> |
| 38 | + <!-- Header section containing title --> |
| 39 | + <header |
| 40 | + class="mdl-layout__header mdl-color-text--white mdl-color--light-blue-700" |
| 41 | + > |
| 42 | + <div class="mdl-cell mdl-cell--12-col mdl-cell--12-col-tablet mdl-grid"> |
| 43 | + <div |
| 44 | + class="mdl-layout__header-row mdl-cell mdl-cell--12-col mdl-cell--12-col-tablet mdl-cell--8-col-desktop" |
| 45 | + > |
| 46 | + <a href="/"><h3>Firebase Authentication</h3></a> |
| 47 | + </div> |
135 | 48 | </div> |
136 | | - <div class="mdl-card__supporting-text mdl-color-text--grey-600"> |
137 | | - <p>Log in with your Microsoft account below.</p> |
138 | | - |
139 | | - <!-- Button that handles sign-in/sign-out --> |
140 | | - <button disabled class="mdl-button mdl-js-button mdl-button--raised" id="quickstart-sign-in">Log in with Microsoft</button> |
141 | | - |
142 | | - <!-- Container where we'll display the user details --> |
143 | | - <div class="quickstart-user-details-container"> |
144 | | - Firebase sign-in status: <span id="quickstart-sign-in-status">Unknown</span> |
145 | | - <div>Firebase auth <code>currentUser</code> object value:</div> |
146 | | - <pre><code id="quickstart-account-details">null</code></pre> |
147 | | - <div>Microsoft OAuth Access Token:</div> |
148 | | - <pre><code id="quickstart-oauthtoken">null</code></pre> |
| 49 | + </header> |
| 50 | + |
| 51 | + <main class="mdl-layout__content mdl-color--grey-100"> |
| 52 | + <div class="mdl-cell mdl-cell--12-col mdl-cell--12-col-tablet mdl-grid"> |
| 53 | + <!-- Container for the demo --> |
| 54 | + <div |
| 55 | + class="mdl-card mdl-shadow--2dp mdl-cell mdl-cell--12-col mdl-cell--12-col-tablet mdl-cell--12-col-desktop" |
| 56 | + > |
| 57 | + <div |
| 58 | + class="mdl-card__title mdl-color--light-blue-600 mdl-color-text--white" |
| 59 | + > |
| 60 | + <h2 class="mdl-card__title-text"> |
| 61 | + Microsoft Authentication with Popup |
| 62 | + </h2> |
| 63 | + </div> |
| 64 | + <div class="mdl-card__supporting-text mdl-color-text--grey-600"> |
| 65 | + <p>Log in with your Microsoft account below.</p> |
| 66 | + |
| 67 | + <!-- Button that handles sign-in/sign-out --> |
| 68 | + <button |
| 69 | + disabled |
| 70 | + class="mdl-button mdl-js-button mdl-button--raised" |
| 71 | + id="quickstart-sign-in" |
| 72 | + > |
| 73 | + Log in with Microsoft |
| 74 | + </button> |
| 75 | + |
| 76 | + <!-- Container where we'll display the user details --> |
| 77 | + <div class="quickstart-user-details-container"> |
| 78 | + Firebase sign-in status: |
| 79 | + <span id="quickstart-sign-in-status">Unknown</span> |
| 80 | + <div>Firebase auth <code>currentUser</code> object value:</div> |
| 81 | + <pre><code id="quickstart-account-details">null</code></pre> |
| 82 | + <div>Microsoft OAuth Access Token:</div> |
| 83 | + <pre><code id="quickstart-oauthtoken">null</code></pre> |
| 84 | + </div> |
| 85 | + </div> |
149 | 86 | </div> |
150 | 87 | </div> |
151 | | - </div> |
| 88 | + </main> |
152 | 89 | </div> |
153 | | - </main> |
154 | | -</div> |
155 | | -</body> |
| 90 | + |
| 91 | + <script type="module" src="microsoft-popup.ts"></script> |
| 92 | + </body> |
156 | 93 | </html> |
0 commit comments