| 
									
										
										
										
											2017-02-13 14:34:26 -05:00
										 |  |  | <!DOCTYPE html> | 
					
						
							|  |  |  | <html> | 
					
						
							|  |  |  |   <head> | 
					
						
							|  |  |  |     <style> | 
					
						
							|  |  |  |       body { | 
					
						
							|  |  |  |         background-color: #ffcccc; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     </style> | 
					
						
							|  |  |  |   </head> | 
					
						
							|  |  |  |   <body> | 
					
						
							|  |  |  |   OAuth3 RPC | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-01 18:04:25 +00:00
										 |  |  |   <script src="../../assets/oauth3.org/oauth3.core.js"></script> | 
					
						
							| 
									
										
										
										
											2017-02-13 14:34:26 -05:00
										 |  |  |   <script> | 
					
						
							| 
									
										
										
										
											2017-02-21 16:54:37 -07:00
										 |  |  |     ;(function () { | 
					
						
							| 
									
										
										
										
											2017-02-13 14:34:26 -05:00
										 |  |  |     'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-21 16:54:37 -07:00
										 |  |  |     // Taken from oauth3.core.js | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-13 14:34:26 -05:00
										 |  |  |     // TODO what about search within hash? | 
					
						
							|  |  |  |     var prefix = "(" + window.location.hostname + ") [.well-known/oauth3/]"; | 
					
						
							| 
									
										
										
										
											2017-02-21 16:54:37 -07:00
										 |  |  |     var params = OAUTH3.query.parse(window.location.hash || window.location.search); | 
					
						
							| 
									
										
										
										
											2017-11-25 08:09:57 +00:00
										 |  |  |     var urlsafe64; | 
					
						
							|  |  |  |     var redirect; | 
					
						
							|  |  |  |     var err; | 
					
						
							|  |  |  |     var oldRpc; | 
					
						
							|  |  |  |     var sub = params.sub || params.subject; | 
					
						
							|  |  |  |     var subData; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function doRedirect(redirect) { | 
					
						
							|  |  |  |       if (params.debug) { | 
					
						
							|  |  |  |         console.log(prefix, 'params.redirect_uri:', params.redirect_uri); | 
					
						
							|  |  |  |         console.log(prefix, 'redirect'); | 
					
						
							|  |  |  |         console.log(redirect); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-11-20 08:26:52 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       if (!params.debug) { | 
					
						
							|  |  |  |         window.location = redirect; | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         // yes, we're violating the security lint with purpose | 
					
						
							|  |  |  |         document.body.innerHTML += window.location.host + window.location.pathname | 
					
						
							|  |  |  |           + '<br/><br/>You\'ve passed the \'debug\' parameter so we\'re pausing' | 
					
						
							|  |  |  |           + ' to let you look at logs or whatever it is that you intended to do.' | 
					
						
							| 
									
										
										
										
											2017-11-25 08:09:57 +00:00
										 |  |  |           + '<br/><br/>Continue with redirect: <a href="' + redirect + '">' + redirect + '</' + 'a>'; | 
					
						
							| 
									
										
										
										
											2017-11-20 08:26:52 -08:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-25 08:09:57 +00:00
										 |  |  |     function onError(err) { | 
					
						
							|  |  |  |       var redirect = params.redirect_uri + '?' + OAUTH3.query.stringify({ | 
					
						
							|  |  |  |         state: params.state | 
					
						
							|  |  |  |       , error: err.code | 
					
						
							|  |  |  |       , error_description: err.message | 
					
						
							|  |  |  |       , error_uri: err.uri | 
					
						
							|  |  |  |       , debug: params.debug || undefined | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2017-02-13 14:34:26 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-25 08:09:57 +00:00
										 |  |  |       doRedirect(redirect); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function onSuccess(urlsafe64, hasSub) { | 
					
						
							|  |  |  |       if (params.debug) { | 
					
						
							|  |  |  |         console.log(prefix, 'directives'); | 
					
						
							|  |  |  |         console.log(resp); | 
					
						
							| 
									
										
										
										
											2017-02-13 14:34:26 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-25 08:09:57 +00:00
										 |  |  |         console.log(prefix, 'base64'); | 
					
						
							|  |  |  |         console.log(urlsafe64); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-02-13 14:34:26 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |       // TODO try postMessage back to redirect_uri domain right here | 
					
						
							|  |  |  |       // window.postMessage(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-25 08:09:57 +00:00
										 |  |  |       // TODO SECURITY make sure it's https NOT http | 
					
						
							| 
									
										
										
										
											2017-02-13 14:34:26 -05:00
										 |  |  |       // NOTE: this can be only up to 2,083 characters | 
					
						
							| 
									
										
										
										
											2017-02-21 16:54:37 -07:00
										 |  |  |       redirect = params.redirect_uri + '?' + OAUTH3.query.stringify({ | 
					
						
							| 
									
										
										
										
											2017-02-13 14:34:26 -05:00
										 |  |  |         state: params.state | 
					
						
							| 
									
										
										
										
											2017-11-25 08:09:57 +00:00
										 |  |  |       , directives: oldRpc ? urlsafe64 : undefined | 
					
						
							|  |  |  |       , data: !oldRpc ? urlsafe64 : undefined | 
					
						
							|  |  |  |       , sub: hasSub && sub || undefined | 
					
						
							| 
									
										
										
										
											2017-02-13 14:34:26 -05:00
										 |  |  |       , debug: params.debug || undefined | 
					
						
							| 
									
										
										
										
											2017-11-25 08:09:57 +00:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2017-02-13 14:34:26 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-25 08:09:57 +00:00
										 |  |  |       doRedirect(redirect); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (params.debug) { | 
					
						
							|  |  |  |       console.warn(prefix, "DEBUG MODE ENABLED. Automatic redirects disabled."); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       console.log(prefix, 'hash||search:'); | 
					
						
							|  |  |  |       console.log(window.location.hash || window.location.search); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       console.log(prefix, 'params:'); | 
					
						
							|  |  |  |       console.log(params); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ('rpc' !== params.response_type) { | 
					
						
							|  |  |  |       err = new Error("response_type '" + params.response_type + "' is not supported"); | 
					
						
							|  |  |  |       err.code = "E_RESPONSE_TYPE"; | 
					
						
							|  |  |  |       // TODO err.uri | 
					
						
							|  |  |  |       onError(err); | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (params.action) { | 
					
						
							|  |  |  |       oldRpc = true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-25 08:58:58 +00:00
										 |  |  |     var loco = window.location.href.replace(/\/\.well-known.*/, ''); | 
					
						
							|  |  |  |     //var loco = 'sso.hellabit.com'; | 
					
						
							|  |  |  |     var resp; | 
					
						
							| 
									
										
										
										
											2017-11-25 08:09:57 +00:00
										 |  |  |     if (/localstorage/i.test(params._scheme)) { | 
					
						
							|  |  |  |       if (sub) { | 
					
						
							|  |  |  |         subData = localStorage.getItem(sub + '@oauth3.org:issuer'); | 
					
						
							| 
									
										
										
										
											2017-02-13 14:34:26 -05:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-11-25 08:58:58 +00:00
										 |  |  |       resp = subData || localStorage.getItem('oauth3.org:issuer') || loco; | 
					
						
							|  |  |  |       onSuccess(resp, subData && true); | 
					
						
							| 
									
										
										
										
											2017-11-25 08:09:57 +00:00
										 |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     var fileWhiteList = [ | 
					
						
							|  |  |  |       '.well-known/oauth3/directives.json' | 
					
						
							|  |  |  |     , '.well-known/oauth3/scopes.json' | 
					
						
							|  |  |  |     ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (-1 === fileWhiteList.indexOf(params._pathname)) { | 
					
						
							|  |  |  |       err = new Error("No access to requested file: " + params._pathname); | 
					
						
							|  |  |  |       err.code = "E_ACCESS_DENIED" | 
					
						
							|  |  |  |       // TODO err.uri | 
					
						
							|  |  |  |       onError(err); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-28 02:26:31 +00:00
										 |  |  |     OAUTH3.request({ url: params._pathname.replace(/^\.well-known\/oauth3\//, '') }).then(function (resp) { | 
					
						
							| 
									
										
										
										
											2017-11-25 08:09:57 +00:00
										 |  |  |       urlsafe64 = OAUTH3._base64.encodeUrlSafe(JSON.stringify(resp.data, null, 0)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       onSuccess(urlsafe64); | 
					
						
							| 
									
										
										
										
											2017-02-13 14:34:26 -05:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-02-21 16:54:37 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     }()); | 
					
						
							| 
									
										
										
										
											2017-02-13 14:34:26 -05:00
										 |  |  |   </script> | 
					
						
							|  |  |  |   </body> | 
					
						
							|  |  |  | </html> |