WIP challenge domain
This commit is contained in:
		
							parent
							
								
									8fe1f4d82a
								
							
						
					
					
						commit
						f54c4dde7a
					
				| @ -3,18 +3,37 @@ | |||||||
|     <title>Telebit Account</title> |     <title>Telebit Account</title> | ||||||
|   </head> |   </head> | ||||||
|   <body> |   <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"> |     <div class="v-app"> | ||||||
|  | 
 | ||||||
|  |       <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> |         <ol> | ||||||
|           <li v-for="domain in domains"> |           <li v-for="domain in domains"> | ||||||
|             {{ domain }} |             {{ domain }} | ||||||
|           </li> |           </li> | ||||||
|         </ol> |         </ol> | ||||||
|  |         <pre><code v-text="token"></code></pre> | ||||||
|  |       </div> | ||||||
|  | 
 | ||||||
|     </div> |     </div> | ||||||
| 
 | 
 | ||||||
|     <!-- development version, includes helpful console warnings --> |     <!-- development version, includes helpful console warnings --> | ||||||
|  | |||||||
| @ -6,62 +6,43 @@ | |||||||
|   , pathname: window.location.pathname.replace(/\/[^\/]*$/, '/') |   , pathname: window.location.pathname.replace(/\/[^\/]*$/, '/') | ||||||
|   }); |   }); | ||||||
|   var $ = function () { return document.querySelector.apply(document, arguments); } |   var $ = function () { return document.querySelector.apply(document, arguments); } | ||||||
| 
 |   var vueData = { | ||||||
|   function onChangeProvider(providerUri) { |     domains: [] | ||||||
|     // example https://oauth3.org
 |   , newDomain: null | ||||||
|     return oauth3.setIdentityProvider(providerUri); |   , 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 () { | ||||||
|   // This opens up the login window for the specified provider
 |         console.log("A new (Email) challenger!", vueData); | ||||||
|   //
 |       } | ||||||
|   function onClickLogin(ev) { |     } | ||||||
|     ev.preventDefault(); |   }); | ||||||
|     ev.stopPropagation(); |  | ||||||
| 
 |  | ||||||
|     var email = $('.js-auth-subject').value; |  | ||||||
| 
 |  | ||||||
|     // TODO check subject for provider viability
 |  | ||||||
|     return oauth3.authenticate({ |  | ||||||
|       subject: email |  | ||||||
|     , scope: 'email@oauth3.org' |  | ||||||
|     }).then(function (session) { |  | ||||||
| 
 |  | ||||||
|       console.info('Authentication was Successful:'); |  | ||||||
|       console.log(session); |  | ||||||
| 
 |  | ||||||
|       // You can use the PPID (or preferably a hash of it) as the login for your app
 |  | ||||||
|       // (it securely functions as both username and password which is known only by your app)
 |  | ||||||
|       // If you use a hash of it as an ID, you can also use the PPID itself as a decryption key
 |  | ||||||
|       //
 |  | ||||||
|       console.info('Secure PPID (aka subject):', session.token.sub); |  | ||||||
| 
 | 
 | ||||||
|   function listStuff(data) { |   function listStuff(data) { | ||||||
|     //window.alert("TODO: show authorized devices, domains, and connectivity information");
 |     //window.alert("TODO: show authorized devices, domains, and connectivity information");
 | ||||||
|         var app6 = new Vue({ |     vueData.hasAccount = true; | ||||||
|           el: '.v-app', |     vueData.domains = data.domains; | ||||||
|           data: { |  | ||||||
|             domains: data.domains |  | ||||||
|           } |  | ||||||
|         }); |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|       return oauth3.request({ |   var sessionStr = localStorage.getItem('session'); | ||||||
|         url: 'https://api.oauth3.org/api/issuer@oauth3.org/jwks/:sub/:kid.json' |   var session; | ||||||
|           .replace(/:sub/g, session.token.sub) |   if (sessionStr) { | ||||||
|           .replace(/:kid/g, session.token.iss) |     try { | ||||||
|       , session: session |       session = JSON.parse(sessionStr); | ||||||
|       }).then(function (resp) { |     } catch(e) { | ||||||
|         console.info("Public Key:"); |       // ignore
 | ||||||
|         console.log(resp.data); |     } | ||||||
| 
 |   } | ||||||
|         return oauth3.request({ |  | ||||||
|           url: 'https://api.oauth3.org/api/issuer@oauth3.org/acl/profile' |  | ||||||
|         , session: session |  | ||||||
|         }).then(function (resp) { |  | ||||||
| 
 |  | ||||||
|           console.info("Inspect Token:"); |  | ||||||
|           console.log(resp.data); |  | ||||||
| 
 | 
 | ||||||
|  |   function loadAccount(session) { | ||||||
|     return oauth3.request({ |     return oauth3.request({ | ||||||
|       url: 'https://api.' + location.hostname + '/api/telebit.cloud/account' |       url: 'https://api.' + location.hostname + '/api/telebit.cloud/account' | ||||||
|     , session: session |     , session: session | ||||||
| @ -95,8 +76,55 @@ | |||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|     }); |     }); | ||||||
|  |   } | ||||||
| 
 | 
 | ||||||
|  |   function onChangeProvider(providerUri) { | ||||||
|  |     // example https://oauth3.org
 | ||||||
|  |     return oauth3.setIdentityProvider(providerUri); | ||||||
|  |   } | ||||||
| 
 | 
 | ||||||
|  |   // This opens up the login window for the specified provider
 | ||||||
|  |   //
 | ||||||
|  |   function onClickLogin(ev) { | ||||||
|  |     ev.preventDefault(); | ||||||
|  |     ev.stopPropagation(); | ||||||
|  | 
 | ||||||
|  |     var email = $('.js-auth-subject').value; | ||||||
|  | 
 | ||||||
|  |     // TODO check subject for provider viability
 | ||||||
|  |     return oauth3.authenticate({ | ||||||
|  |       subject: email | ||||||
|  |     , scope: 'email@oauth3.org' | ||||||
|  |     }).then(function (session) { | ||||||
|  | 
 | ||||||
|  |       console.info('Authentication was Successful:'); | ||||||
|  |       console.log(session); | ||||||
|  | 
 | ||||||
|  |       // You can use the PPID (or preferably a hash of it) as the login for your app
 | ||||||
|  |       // (it securely functions as both username and password which is known only by your app)
 | ||||||
|  |       // If you use a hash of it as an ID, you can also use the PPID itself as a decryption key
 | ||||||
|  |       //
 | ||||||
|  |       console.info('Secure PPID (aka subject):', session.token.sub); | ||||||
|  | 
 | ||||||
|  |       return oauth3.request({ | ||||||
|  |         url: 'https://api.oauth3.org/api/issuer@oauth3.org/jwks/:sub/:kid.json' | ||||||
|  |           .replace(/:sub/g, session.token.sub) | ||||||
|  |           .replace(/:kid/g, session.token.iss) | ||||||
|  |       , session: session | ||||||
|  |       }).then(function (resp) { | ||||||
|  |         console.info("Public Key:"); | ||||||
|  |         console.log(resp.data); | ||||||
|  | 
 | ||||||
|  |         return oauth3.request({ | ||||||
|  |           url: 'https://api.oauth3.org/api/issuer@oauth3.org/acl/profile' | ||||||
|  |         , session: session | ||||||
|  |         }).then(function (resp) { | ||||||
|  | 
 | ||||||
|  |           console.info("Inspect Token:"); | ||||||
|  |           console.log(resp.data); | ||||||
|  | 
 | ||||||
|  |           localStorage.setItem('session', JSON.stringify(session)); | ||||||
|  |           loadAccount(session) | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|       }); |       }); | ||||||
| @ -109,4 +137,8 @@ | |||||||
| 
 | 
 | ||||||
|   $('body form.js-auth-form').addEventListener('submit', onClickLogin); |   $('body form.js-auth-form').addEventListener('submit', onClickLogin); | ||||||
|   onChangeProvider('oauth3.org'); |   onChangeProvider('oauth3.org'); | ||||||
|  |   if (session) { | ||||||
|  |     vueData.token = session.access_token | ||||||
|  |     loadAccount(session); | ||||||
|  |   } | ||||||
| }()); | }()); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user