bugfixes
This commit is contained in:
		
							parent
							
								
									203bd24368
								
							
						
					
					
						commit
						fbce24e14a
					
				| @ -5,7 +5,7 @@ | |||||||
|   var OAUTH3_CORE = exports.OAUTH3_CORE; |   var OAUTH3_CORE = exports.OAUTH3_CORE; | ||||||
| 
 | 
 | ||||||
|   function getDefaultAppUrl() { |   function getDefaultAppUrl() { | ||||||
|     console.warn('[deprecated] using window.location.{protocol, host, pathname} when opts.appUrl should be used'); |     console.warn('[deprecated] using window.location.{protocol, host, pathname} when opts.client_id should be used'); | ||||||
|     return window.location.protocol |     return window.location.protocol | ||||||
|       + '//' + window.location.host |       + '//' + window.location.host | ||||||
|       + (window.location.pathname).replace(/\/?$/, '') |       + (window.location.pathname).replace(/\/?$/, '') | ||||||
| @ -23,8 +23,9 @@ | |||||||
|       opts = opts || {}; |       opts = opts || {}; | ||||||
|       opts.debug = true; |       opts.debug = true; | ||||||
|       providerUri = OAUTH3_CORE.normalizeUrl(providerUri); |       providerUri = OAUTH3_CORE.normalizeUrl(providerUri); | ||||||
|       var discObj = OAUTH3_CORE.urls.discover(providerUri, { appUrl: (opts.appUrl || getDefaultAppUrl()), debug: opts.debug }); |       var discObj = OAUTH3_CORE.urls.discover(providerUri, { client_id: (opts.client_id || opts.client_uri || getDefaultAppUrl()), debug: opts.debug }); | ||||||
| 
 | 
 | ||||||
|  |       // TODO ability to reuse iframe instead of closing
 | ||||||
|       return browser.insertIframe(discObj.url, discObj.state, opts).then(function (params) { |       return browser.insertIframe(discObj.url, discObj.state, opts).then(function (params) { | ||||||
|         if (params.error) { |         if (params.error) { | ||||||
|           return OAUTH3_CORE.formatError(providerUri, params.error); |           return OAUTH3_CORE.formatError(providerUri, params.error); | ||||||
| @ -108,7 +109,6 @@ | |||||||
| 
 | 
 | ||||||
|   , openWindow: function (url, state, opts) { |   , openWindow: function (url, state, opts) { | ||||||
|       var promise = new OAUTH3.PromiseA(function (resolve, reject) { |       var promise = new OAUTH3.PromiseA(function (resolve, reject) { | ||||||
|         var winref; |  | ||||||
|         var tok; |         var tok; | ||||||
| 
 | 
 | ||||||
|         function cleanup() { |         function cleanup() { | ||||||
| @ -117,10 +117,13 @@ | |||||||
|           tok = null; |           tok = null; | ||||||
|           // this is last in case the window self-closes synchronously
 |           // this is last in case the window self-closes synchronously
 | ||||||
|           // (should never happen, but that's a negotiable implementation detail)
 |           // (should never happen, but that's a negotiable implementation detail)
 | ||||||
|           //winref.close();
 |           if (!opts.reuseWindow) { | ||||||
|  |             promise.child.close(); | ||||||
|  |           } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         window['--oauth3-callback-' + state] = function (params) { |         window['--oauth3-callback-' + state] = function (params) { | ||||||
|  |           console.log('YOLO!!'); | ||||||
|           resolve(params); |           resolve(params); | ||||||
|           cleanup(); |           cleanup(); | ||||||
|         }; |         }; | ||||||
| @ -132,18 +135,20 @@ | |||||||
|           cleanup(); |           cleanup(); | ||||||
|         }, opts.timeout || 3 * 60 * 1000); |         }, opts.timeout || 3 * 60 * 1000); | ||||||
| 
 | 
 | ||||||
|         // TODO allow size changes (via directive even)
 |         setTimeout(function () { | ||||||
|         winref = window.open( |           if (!promise.child) { | ||||||
|           url |  | ||||||
|         , 'oauth3-login-' + state |  | ||||||
|         , 'height=' + (opts.height || 720) + ',width=' + (opts.width || 620) |  | ||||||
|         ); |  | ||||||
|         if (!winref) { |  | ||||||
|             reject("TODO: open the iframe first and discover oauth3 directives before popup"); |             reject("TODO: open the iframe first and discover oauth3 directives before popup"); | ||||||
|             cleanup(); |             cleanup(); | ||||||
|           } |           } | ||||||
|  |         }, 0); | ||||||
|       }); |       }); | ||||||
| 
 | 
 | ||||||
|  |       // TODO allow size changes (via directive even)
 | ||||||
|  |       promise.child = window.open( | ||||||
|  |         url | ||||||
|  |       , 'oauth3-login-' + (opts.reuseWindow || state) | ||||||
|  |       , 'height=' + (opts.height || 720) + ',width=' + (opts.width || 620) | ||||||
|  |       ); | ||||||
|       // TODO periodically garbage collect expired handlers from window object
 |       // TODO periodically garbage collect expired handlers from window object
 | ||||||
|       return promise; |       return promise; | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -210,14 +210,14 @@ | |||||||
|     if (!providerUri) { |     if (!providerUri) { | ||||||
|       throw new Error("cannot discover without providerUri"); |       throw new Error("cannot discover without providerUri"); | ||||||
|     } |     } | ||||||
|     if (!opts.appUrl) { |     if (!opts.client_id) { | ||||||
|       throw new Error("cannot discover without opts.appUrl"); |       throw new Error("cannot discover without options.client_id"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     var params = { |     var params = { | ||||||
|       action: 'directives' |       action: 'directives' | ||||||
|     , state: core.utils.randomState() |     , state: core.utils.randomState() | ||||||
|     , redirect_uri: opts.appUrl + (opts.appCallbackPath || '/.well-known/oauth3/callback.html') |     , redirect_uri: opts.client_id + (opts.client_callback_path || '/.well-known/oauth3/callback.html') | ||||||
|     , response_type: 'rpc' |     , response_type: 'rpc' | ||||||
|     , _method: 'GET' |     , _method: 'GET' | ||||||
|     , _pathname: '.well-known/oauth3/directives.json' |     , _pathname: '.well-known/oauth3/directives.json' | ||||||
| @ -336,7 +336,8 @@ | |||||||
| 
 | 
 | ||||||
|     var redirectUri = opts.redirectUri; |     var redirectUri = opts.redirectUri; | ||||||
|     var scope = opts.scope || directive.authn_scope; |     var scope = opts.scope || directive.authn_scope; | ||||||
|     var clientId = opts.appId || opts.clientId || opts.clientUri; |     var clientId = core.normalizeUri(opts.client_id || opts.client_uri | ||||||
|  |         || opts.appId || opts.clientId || opts.clientUri); | ||||||
|     var args = directive[type]; |     var args = directive[type]; | ||||||
|     var uri = args.url; |     var uri = args.url; | ||||||
|     var state = core.utils.randomState(); |     var state = core.utils.randomState(); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user