shortcut discover + authorization_dialog
This commit is contained in:
		
							parent
							
								
									4ca48db78b
								
							
						
					
					
						commit
						c483058fa8
					
				| @ -38,6 +38,63 @@ | |||||||
|       }); |       }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |   , discoverAuthorizationDialog: function(providerUri, opts) { | ||||||
|  |       var discObj = OAUTH3.core.discover(providerUri, opts); | ||||||
|  | 
 | ||||||
|  |       // hmm... we're gonna need a broker for this since switching windows is distracting,
 | ||||||
|  |       // popups are obnoxious, iframes are sometimes blocked, and most servers don't implement CORS
 | ||||||
|  |       // eventually it should be the browser (and postMessage may be a viable option now), but whatever...
 | ||||||
|  | 
 | ||||||
|  |       // TODO allow postMessage from providerUri in addition to callback
 | ||||||
|  |       var discWin = OAUTH3.openWindow(discObj.url, discObj.state, { reuseWindow: 'conquerer' }); | ||||||
|  |       return discWin.then(function (params) { | ||||||
|  |         console.log('discwin params'); | ||||||
|  |         console.log(params); | ||||||
|  |         // discWin.child
 | ||||||
|  |         // TODO params should have response_type indicating json, binary, etc
 | ||||||
|  |         var directives = JSON.parse(atob(OAUTH3.core.utils.urlSafeBase64ToBase64(params.result || params.directives))); | ||||||
|  |         console.log('directives'); | ||||||
|  |         console.log(directives); | ||||||
|  | 
 | ||||||
|  |         // Do some stuff
 | ||||||
|  |         var authObj = OAUTH3.core.implicitGrant( | ||||||
|  |           directives | ||||||
|  |         , { redirect_uri: opts.redirect_uri | ||||||
|  |           , debug: opts.debug | ||||||
|  |           , client_id: opts.client_id || opts.client_uri | ||||||
|  |           , client_uri: opts.client_uri || opts.client_id | ||||||
|  |           } | ||||||
|  |         ); | ||||||
|  | 
 | ||||||
|  |         if (params.debug) { | ||||||
|  |           window.alert("DEBUG MODE: Pausing so you can look at logs and whatnot :) Fire at will!"); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return new OAUTH3.PromiseA(function (resolve, reject) { | ||||||
|  |           // TODO check if authObj.url is relative or full
 | ||||||
|  |           discWin.child.location = OAUTH3.core.urls.resolve(providerUri, authObj.url); | ||||||
|  | 
 | ||||||
|  |           if (params.debug) { | ||||||
|  |             discWin.child.focus(); | ||||||
|  |           } | ||||||
|  | 
 | ||||||
|  |           window['--oauth3-callback-' + authObj.state] = function (tokens) { | ||||||
|  |             if (tokens.error) { | ||||||
|  |               return reject(OAUTH3.core.formatError(tokens.error)); | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             if (params.debug || tokens.debug) { | ||||||
|  |               if (window.confirm("DEBUG MODE: okay to close oauth3 window?")) { | ||||||
|  |                 discWin.child.close(); | ||||||
|  |               } | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             resolve(tokens); | ||||||
|  |           }; | ||||||
|  |         }); | ||||||
|  |       }); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|   , frameRequest: function (url, state, opts) { |   , frameRequest: function (url, state, opts) { | ||||||
|       var promise; |       var promise; | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user