mirror of
				https://github.com/therootcompany/keyfetch.js.git
				synced 2024-11-16 17:29:02 +00:00 
			
		
		
		
	v1.1.2: DRY key check loop
This commit is contained in:
		
							parent
							
								
									6c071af9cd
								
							
						
					
					
						commit
						6d5c9d0097
					
				
							
								
								
									
										54
									
								
								keyfetch.js
									
									
									
									
									
								
							
							
						
						
									
										54
									
								
								keyfetch.js
									
									
									
									
									
								
							| @ -111,16 +111,11 @@ keyfetch.oidcJwks = function (iss) { | ||||
|     }); | ||||
|   }); | ||||
| }; | ||||
| keyfetch.oidcJwk = function (id, iss) { | ||||
|   // TODO [2] DRY this up a bit
 | ||||
|   return keyfetch._checkCache(id, iss).then(function (hit) { | ||||
|     if (hit) { | ||||
|       return Promise.resolve(hit); | ||||
|     } | ||||
| 
 | ||||
|     return keyfetch.oidcJwks(iss).then(function (results) { | ||||
| function checkId(id) { | ||||
|   return function (results) { | ||||
|     var result = results.some(function (result) { | ||||
|       // we already checked iss above
 | ||||
|       console.log(result); | ||||
|       return result.jwk.kid === id || result.thumbprint === id; | ||||
|     })[0]; | ||||
| 
 | ||||
| @ -128,47 +123,24 @@ keyfetch.oidcJwk = function (id, iss) { | ||||
|       throw new Error("No JWK found by kid or thumbprint '" + id + "'"); | ||||
|     } | ||||
|     return result; | ||||
|     }); | ||||
|   }; | ||||
| } | ||||
| keyfetch.oidcJwk = function (id, iss) { | ||||
|   return keyfetch._checkCache(id, iss).then(function (hit) { | ||||
|     if (hit) { return hit; } | ||||
|     return keyfetch.oidcJwks(iss).then(checkId(id)); | ||||
|   }); | ||||
| }; | ||||
| keyfetch.wellKnownJwk = function (id, iss) { | ||||
|   // TODO [2] DRY this up a bit
 | ||||
|   return keyfetch._checkCache(id, iss).then(function (hit) { | ||||
|     if (hit) { | ||||
|       return Promise.resolve(hit); | ||||
|     } | ||||
| 
 | ||||
|     return keyfetch.wellKnownJwks(iss).then(function (results) { | ||||
|       var result = results.some(function (result) { | ||||
|         // we already checked iss above
 | ||||
|         return result.jwk.kid === id || result.thumbprint === id; | ||||
|       })[0]; | ||||
| 
 | ||||
|       if (!result) { | ||||
|         throw new Error("No JWK found by kid or thumbprint '" + id + "'"); | ||||
|       } | ||||
|       return result; | ||||
|     }); | ||||
|     if (hit) { return hit; } | ||||
|     return keyfetch.wellKnownJwks(iss).then(checkId(id)); | ||||
|   }); | ||||
| }; | ||||
| keyfetch.jwk = function (id, jwksUrl) { | ||||
|   // TODO [2] DRY this up a bit
 | ||||
|   return keyfetch._checkCache(id, jwksUrl).then(function (hit) { | ||||
|     if (hit) { | ||||
|       return Promise.resolve(hit); | ||||
|     } | ||||
| 
 | ||||
|     return keyfetch.jwks(jwksUrl).then(function (results) { | ||||
|       var result = results.some(function (result) { | ||||
|         // we already checked iss above
 | ||||
|         return result.jwk.kid === id || result.thumbprint === id; | ||||
|       })[0]; | ||||
| 
 | ||||
|       if (!result) { | ||||
|         throw new Error("No JWK found by kid or thumbprint '" + id + "'"); | ||||
|       } | ||||
|       return result; | ||||
|     }); | ||||
|     if (hit) { return hit; } | ||||
|     return keyfetch.jwks(jwksUrl).then(checkId(id)); | ||||
|   }); | ||||
| }; | ||||
| keyfetch._checkCache = function (id, iss) { | ||||
|  | ||||
| @ -31,5 +31,5 @@ | ||||
|   "scripts": { | ||||
|     "test": "echo \"Error: no test specified\" && exit 1" | ||||
|   }, | ||||
|   "version": "1.1.1" | ||||
|   "version": "1.1.2" | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user