| 
									
										
										
										
											2017-02-13 14:34:26 -05:00
										 |  |  | <!DOCTYPE html> | 
					
						
							|  |  |  | <html> | 
					
						
							|  |  |  |   <head> | 
					
						
							|  |  |  |     <style> | 
					
						
							|  |  |  |       body { | 
					
						
							|  |  |  |         background-color: #ffcccc; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     </style> | 
					
						
							|  |  |  |   </head> | 
					
						
							|  |  |  |   <body> | 
					
						
							|  |  |  |   OAuth3 RPC | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   <script src="/assets/org.oauth3/oauth3.core.js"></script> | 
					
						
							|  |  |  |   <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-02-13 14:34:26 -05:00
										 |  |  |     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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-21 16:54:37 -07:00
										 |  |  |     OAUTH3.request({ url: 'directives.json' }).then(function (resp) { | 
					
						
							| 
									
										
										
										
											2017-02-21 17:05:23 -07:00
										 |  |  |       var urlsafe64 = OAUTH3._base64.encodeUrlSafe(JSON.stringify(resp.data, null, 0)); | 
					
						
							| 
									
										
										
										
											2017-02-13 14:34:26 -05:00
										 |  |  |       var redirect; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       console.log(prefix, 'directives'); | 
					
						
							|  |  |  |       console.log(resp); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       console.log(prefix, 'base64'); | 
					
						
							|  |  |  |       console.log(urlsafe64); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // TODO try postMessage back to redirect_uri domain right here | 
					
						
							|  |  |  |       // window.postMessage(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // TODO make sure it's https NOT http | 
					
						
							|  |  |  |       // NOTE: this can be only up to 2,083 characters | 
					
						
							|  |  |  |       console.log(prefix, 'params.redirect_uri:', params.redirect_uri); | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  |       , directives: urlsafe64 | 
					
						
							|  |  |  |       , debug: params.debug || undefined | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       console.log(prefix, 'redirect'); | 
					
						
							|  |  |  |       console.log(redirect); | 
					
						
							|  |  |  |       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.' | 
					
						
							|  |  |  |           + '<br/><br/>Continue with redirect: <a href="' + redirect + '">' + redirect + '</' + 'a>'; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-02-21 16:54:37 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     }()); | 
					
						
							| 
									
										
										
										
											2017-02-13 14:34:26 -05:00
										 |  |  |   </script> | 
					
						
							|  |  |  |   </body> | 
					
						
							|  |  |  | </html> |