misc bug fixes
This commit is contained in:
		
							parent
							
								
									516eda4ea6
								
							
						
					
					
						commit
						623d94e045
					
				| @ -246,7 +246,7 @@ | |||||||
|         if (!OAUTH3.crypto) { |         if (!OAUTH3.crypto) { | ||||||
|           return OAUTH3.PromiseA.reject(new Error("OAuth3 crypto library unavailable")); |           return OAUTH3.PromiseA.reject(new Error("OAuth3 crypto library unavailable")); | ||||||
|         } |         } | ||||||
|         jwk = jwk.privateKey || jwk; |         jwk = jwk.private_key || jwk.privateKey || jwk; | ||||||
| 
 | 
 | ||||||
|         var prom; |         var prom; | ||||||
|         if (jwk.kid) { |         if (jwk.kid) { | ||||||
| @ -1151,7 +1151,7 @@ | |||||||
|     , set: function (providerUri, newSession, id) { |     , set: function (providerUri, newSession, id) { | ||||||
|         var str = JSON.stringify(newSession); |         var str = JSON.stringify(newSession); | ||||||
|         window.sessionStorage.setItem(this.prefix + providerUri, str); |         window.sessionStorage.setItem(this.prefix + providerUri, str); | ||||||
|         id = id || newSession.id || newSession.token.token.id; |         id = id || newSession.id || newSession.token.sub || newSession.token.id; | ||||||
|         if (id) { |         if (id) { | ||||||
|           window.sessionStorage.setItem(this.prefix + providerUri + id, str); |           window.sessionStorage.setItem(this.prefix + providerUri + id, str); | ||||||
|         } |         } | ||||||
| @ -1161,14 +1161,14 @@ | |||||||
|         var prefix = this.prefix + (providerUri || ''); |         var prefix = this.prefix + (providerUri || ''); | ||||||
|         var result = {}; |         var result = {}; | ||||||
|         OAUTH3._defaultStorage._getStorageKeys(prefix, window.sessionStorage).forEach(function (key) { |         OAUTH3._defaultStorage._getStorageKeys(prefix, window.sessionStorage).forEach(function (key) { | ||||||
|           result[key.replace(prefix, '')] = JSON.parse(window.localStorage.getItem(key) || 'null'); |           result[key.replace(prefix, '')] = JSON.parse(window.sessionStorage.getItem(key) || 'null'); | ||||||
|         }); |         }); | ||||||
|         return OAUTH3.PromiseA.resolve(result); |         return OAUTH3.PromiseA.resolve(result); | ||||||
|       } |       } | ||||||
|     , clear: function (providerUri) { |     , clear: function (providerUri) { | ||||||
|         var prefix = this.prefix + (providerUri || ''); |         var prefix = this.prefix + (providerUri || ''); | ||||||
|         OAUTH3._defaultStorage._getStorageKeys(prefix, window.sessionStorage).forEach(function (key) { |         OAUTH3._defaultStorage._getStorageKeys(prefix, window.sessionStorage).forEach(function (key) { | ||||||
|           window.localStorage.removeItem(key); |           window.sessionStorage.removeItem(key); | ||||||
|         }); |         }); | ||||||
|         return OAUTH3.PromiseA.resolve(); |         return OAUTH3.PromiseA.resolve(); | ||||||
|       } |       } | ||||||
|  | |||||||
| @ -538,13 +538,14 @@ OAUTH3.authz.redirectWithToken = function (providerUri, session, clientParams, s | |||||||
|       var signProms = []; |       var signProms = []; | ||||||
|       signProms.push(OAUTH3.jwt.sign(Object.assign({ |       signProms.push(OAUTH3.jwt.sign(Object.assign({ | ||||||
|         exp: calcExpiration(clientParams.exp || '1h', now) |         exp: calcExpiration(clientParams.exp || '1h', now) | ||||||
|       }, payload))); |       }, payload), keyPair)); | ||||||
|       // if (clientParams.refresh_token) {
 |       // if (clientParams.refresh_token) {
 | ||||||
|         signProms.push(OAUTH3.jwt.sign(Object.assign({ |         signProms.push(OAUTH3.jwt.sign(Object.assign({ | ||||||
|           exp: calcExpiration(clientParams.refresh_exp, now) |           exp: calcExpiration(clientParams.refresh_exp, now) | ||||||
|         }, payload))); |         }, payload), keyPair)); | ||||||
|       // }
 |       // }
 | ||||||
|       return OAUTH3.PromiseA.all(signProms).then(function (tokens) { |       return OAUTH3.PromiseA.all(signProms).then(function (tokens) { | ||||||
|  |         console.log('created new tokens for client'); | ||||||
|         return { |         return { | ||||||
|           access_token: tokens[0] |           access_token: tokens[0] | ||||||
|         , refresh_token: tokens[1] |         , refresh_token: tokens[1] | ||||||
| @ -558,6 +559,7 @@ OAUTH3.authz.redirectWithToken = function (providerUri, session, clientParams, s | |||||||
|     // TODO inform client not to persist token
 |     // TODO inform client not to persist token
 | ||||||
|     OAUTH3.url.redirect(clientParams, scopes, session); |     OAUTH3.url.redirect(clientParams, scopes, session); | ||||||
|   }, function (err) { |   }, function (err) { | ||||||
|  |     console.error('unexpected error creating client tokens', err); | ||||||
|     OAUTH3.url.redirect(clientParams, scopes, {error: err}); |     OAUTH3.url.redirect(clientParams, scopes, {error: err}); | ||||||
|   }); |   }); | ||||||
| }; | }; | ||||||
| @ -637,7 +639,7 @@ OAUTH3.hooks.grants = { | |||||||
|     if (!clientUri) { |     if (!clientUri) { | ||||||
|       throw new Error("clientUri is not set"); |       throw new Error("clientUri is not set"); | ||||||
|     } |     } | ||||||
|     return OAUTH3.PromiseA.resolve(OAUTH3._hooks.grants.get(OAUTH3.uri.normalize(clientUri))); |     return OAUTH3.PromiseA.resolve(OAUTH3._hooks.grants.get(id, OAUTH3.uri.normalize(clientUri))); | ||||||
|   } |   } | ||||||
| , set: function (id, clientUri, grants) { | , set: function (id, clientUri, grants) { | ||||||
|     OAUTH3.hooks._checkStorage('grants', 'set'); |     OAUTH3.hooks._checkStorage('grants', 'set'); | ||||||
| @ -648,7 +650,7 @@ OAUTH3.hooks.grants = { | |||||||
|     if (!clientUri) { |     if (!clientUri) { | ||||||
|       throw new Error("clientUri is not set"); |       throw new Error("clientUri is not set"); | ||||||
|     } |     } | ||||||
|     return OAUTH3.PromiseA.resolve(OAUTH3._hooks.grants.set(OAUTH3.uri.normalize(clientUri), grants)); |     return OAUTH3.PromiseA.resolve(OAUTH3._hooks.grants.set(id, OAUTH3.uri.normalize(clientUri), grants)); | ||||||
|   } |   } | ||||||
| , all: function () { | , all: function () { | ||||||
|     OAUTH3.hooks._checkStorage('grants', 'all'); |     OAUTH3.hooks._checkStorage('grants', 'all'); | ||||||
| @ -721,7 +723,8 @@ OAUTH3.hooks.session.get = function (providerUri, id) { | |||||||
|         console.error("too many users, don't know which key to use"); |         console.error("too many users, don't know which key to use"); | ||||||
|       } |       } | ||||||
|       if (!pair) { |       if (!pair) { | ||||||
|         return null; |         // even if the access token isn't fresh, the session might have a refresh token
 | ||||||
|  |         return session; | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       var now = Math.floor(Date.now()/1000); |       var now = Math.floor(Date.now()/1000); | ||||||
| @ -735,6 +738,7 @@ OAUTH3.hooks.session.get = function (providerUri, id) { | |||||||
|       , exp: now + 3600 |       , exp: now + 3600 | ||||||
|       }; |       }; | ||||||
|       return OAUTH3.jwt.sign(payload, pair.privateKey).then(function (token) { |       return OAUTH3.jwt.sign(payload, pair.privateKey).then(function (token) { | ||||||
|  |         console.log('created new token for provider'); | ||||||
|         return OAUTH3.hooks.session.refresh( |         return OAUTH3.hooks.session.refresh( | ||||||
|           { provider_uri: providerUri, client_uri: providerUri || providerUri } |           { provider_uri: providerUri, client_uri: providerUri || providerUri } | ||||||
|         , { access_token: token } |         , { access_token: token } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user