WIP challenge domain
This commit is contained in:
		
							parent
							
								
									8fe1f4d82a
								
							
						
					
					
						commit
						f54c4dde7a
					
				| @ -3,18 +3,37 @@ | ||||
|     <title>Telebit Account</title> | ||||
|   </head> | ||||
|   <body> | ||||
|     <h1>Login</h1> | ||||
|     <form class="js-auth-form"> | ||||
|       <input class="js-auth-subject" placeholder="email" type="email"/> | ||||
|       <button class="js-auth-submit" type="submit">Login</button> | ||||
|     </form> | ||||
| 
 | ||||
|     <div class="v-app"> | ||||
| 			<ol> | ||||
| 				<li v-for="domain in domains"> | ||||
| 					{{ domain }} | ||||
| 				</li> | ||||
| 			</ol> | ||||
| 
 | ||||
|       <div v-if="!hasAccount"> | ||||
|         <h1>Login</h1> | ||||
|         <form class="js-auth-form"> | ||||
|           <input class="js-auth-subject" placeholder="email" type="email" required/> | ||||
|           <button class="js-auth-submit" type="submit">Login</button> | ||||
|         </form> | ||||
|       </div> | ||||
| 
 | ||||
|       <div v-if="hasAccount"> | ||||
|         <h1>Account</h1> | ||||
|         <form v-on:submit="challengeDns()"> | ||||
|           Add a custom domain: | ||||
|           <input v-model="newDomain" placeholder="example.com" type="text" required/> | ||||
|           <button type="submit">Next</button> | ||||
|         </form> | ||||
|         <form v-on:submit="challengeEmail()"> | ||||
|           Authorize another email: | ||||
|           <input v-model="newEmail" placeholder="jon@example.com" type="email" required/> | ||||
|           <button type="submit">Next</button> | ||||
|         </form> | ||||
|         <ol> | ||||
|           <li v-for="domain in domains"> | ||||
|             {{ domain }} | ||||
|           </li> | ||||
|         </ol> | ||||
|         <pre><code v-text="token"></code></pre> | ||||
|       </div> | ||||
| 
 | ||||
|     </div> | ||||
| 
 | ||||
|     <!-- development version, includes helpful console warnings --> | ||||
|  | ||||
| @ -6,6 +6,77 @@ | ||||
|   , pathname: window.location.pathname.replace(/\/[^\/]*$/, '/') | ||||
|   }); | ||||
|   var $ = function () { return document.querySelector.apply(document, arguments); } | ||||
|   var vueData = { | ||||
|     domains: [] | ||||
|   , newDomain: null | ||||
|   , newEmail: null | ||||
|   , hasAccount: false | ||||
|   , token: null | ||||
|   }; | ||||
|   var app = new Vue({ | ||||
|     el: '.v-app' | ||||
|   , data: vueData | ||||
|   , methods: { | ||||
|       challengeDns: function () { | ||||
|         console.log("A new (DNS) challenger!", vueData); | ||||
|       } | ||||
|     , challengeEmail: function () { | ||||
|         console.log("A new (Email) challenger!", vueData); | ||||
|       } | ||||
|     } | ||||
|   }); | ||||
| 
 | ||||
|   function listStuff(data) { | ||||
|     //window.alert("TODO: show authorized devices, domains, and connectivity information");
 | ||||
|     vueData.hasAccount = true; | ||||
|     vueData.domains = data.domains; | ||||
|   } | ||||
| 
 | ||||
|   var sessionStr = localStorage.getItem('session'); | ||||
|   var session; | ||||
|   if (sessionStr) { | ||||
|     try { | ||||
|       session = JSON.parse(sessionStr); | ||||
|     } catch(e) { | ||||
|       // ignore
 | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   function loadAccount(session) { | ||||
|     return oauth3.request({ | ||||
|       url: 'https://api.' + location.hostname + '/api/telebit.cloud/account' | ||||
|     , session: session | ||||
|     }).then(function (resp) { | ||||
| 
 | ||||
|       console.info("Telebit Account:"); | ||||
|       console.log(resp.data); | ||||
| 
 | ||||
|       if (resp.data && resp.data.domains) { | ||||
|         listStuff(resp.data); | ||||
|         return; | ||||
|       } | ||||
| 
 | ||||
|       if (1 === resp.data.accounts.length) { | ||||
|         listStuff(resp); | ||||
|       } else if (0 === resp.data.accounts.length) { | ||||
|         return oauth3.request({ | ||||
|           url: 'https://api.' + location.hostname + 'api/telebit.cloud/account' | ||||
|         , method: 'POST' | ||||
|         , session: session | ||||
|         , body: { | ||||
|             email: email | ||||
|           } | ||||
|         }).then(function (resp) { | ||||
|           listStuff(resp); | ||||
|         }); | ||||
|       } if (resp.data.accounts.length > 2) { | ||||
|         window.alert("Multiple accounts."); | ||||
|       } else { | ||||
|         window.alert("Bad response."); | ||||
|       } | ||||
| 
 | ||||
|     }); | ||||
|   } | ||||
| 
 | ||||
|   function onChangeProvider(providerUri) { | ||||
|     // example https://oauth3.org
 | ||||
| @ -35,16 +106,6 @@ | ||||
|       //
 | ||||
|       console.info('Secure PPID (aka subject):', session.token.sub); | ||||
| 
 | ||||
|       function listStuff(data) { | ||||
|         //window.alert("TODO: show authorized devices, domains, and connectivity information");
 | ||||
|         var app6 = new Vue({ | ||||
|           el: '.v-app', | ||||
|           data: { | ||||
|             domains: data.domains | ||||
|           } | ||||
|         }); | ||||
|       } | ||||
| 
 | ||||
|       return oauth3.request({ | ||||
|         url: 'https://api.oauth3.org/api/issuer@oauth3.org/jwks/:sub/:kid.json' | ||||
|           .replace(/:sub/g, session.token.sub) | ||||
| @ -62,41 +123,8 @@ | ||||
|           console.info("Inspect Token:"); | ||||
|           console.log(resp.data); | ||||
| 
 | ||||
|           return oauth3.request({ | ||||
|             url: 'https://api.' + location.hostname + '/api/telebit.cloud/account' | ||||
|           , session: session | ||||
|           }).then(function (resp) { | ||||
| 
 | ||||
|             console.info("Telebit Account:"); | ||||
|             console.log(resp.data); | ||||
| 
 | ||||
|             if (resp.data && resp.data.domains) { | ||||
|               listStuff(resp.data); | ||||
|               return; | ||||
|             } | ||||
| 
 | ||||
|             if (1 === resp.data.accounts.length) { | ||||
|               listStuff(resp); | ||||
|             } else if (0 === resp.data.accounts.length) { | ||||
|               return oauth3.request({ | ||||
|                 url: 'https://api.' + location.hostname + 'api/telebit.cloud/account' | ||||
|               , method: 'POST' | ||||
|               , session: session | ||||
|               , body: { | ||||
|                   email: email | ||||
|                 } | ||||
|               }).then(function (resp) { | ||||
|                 listStuff(resp); | ||||
|               }); | ||||
|             } if (resp.data.accounts.length > 2) { | ||||
|               window.alert("Multiple accounts."); | ||||
|             } else { | ||||
|               window.alert("Bad response."); | ||||
|             } | ||||
| 
 | ||||
|           }); | ||||
| 
 | ||||
| 
 | ||||
|           localStorage.setItem('session', JSON.stringify(session)); | ||||
|           loadAccount(session) | ||||
|         }); | ||||
| 
 | ||||
|       }); | ||||
| @ -109,4 +137,8 @@ | ||||
| 
 | ||||
|   $('body form.js-auth-form').addEventListener('submit', onClickLogin); | ||||
|   onChangeProvider('oauth3.org'); | ||||
|   if (session) { | ||||
|     vueData.token = session.access_token | ||||
|     loadAccount(session); | ||||
|   } | ||||
| }()); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user