-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented the DPoP token exchange (#411)
- This implements the OAuth2 code exchange step: after an auth code has been returned by the IdP through redirection, the client can use the obtained auth code to get an access token. If the request has a DPoP header, the returned token is bound to the DPoP key. - The mockJwk reference is unefined when setting up the mock, but the mockJwk() function is defined when *calling* the mock. Thanks @Vinnl ! - The oidc module is independant from solid, so it should not depend on the core module, which is meant to be solid-specific. this implies some redundancy in the types implemented in both places, but that means that these types may evolve independantly, while still getting errors in case of incompatibility, which is a good thing. - The endpoint returns a token_type field, which can be used to verify that the token is of the requested type (Bearer or DPoP) Co-authored-by: Vincent <[email protected]>
- Loading branch information
Showing
12 changed files
with
916 additions
and
79 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2020 Inrupt Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to use, | ||
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the | ||
* Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
import URL from "url-parse"; | ||
|
||
export interface IIssuerConfig { | ||
issuer: URL; | ||
authorizationEndpoint: URL; | ||
tokenEndpoint: URL; | ||
userinfoEndpoint?: URL; | ||
jwksUri: URL; | ||
registrationEndpoint?: URL; | ||
scopesSupported?: string[]; | ||
responseTypesSupported?: string[]; | ||
responseModesSupported?: string[]; | ||
grantTypesSupported?: string[]; | ||
acrValuesSupported?: string[]; | ||
subjectTypesSupported: string[]; | ||
idTokenSigningAlgValuesSupported?: string[]; | ||
idTokenEncryptionAlgValuesSupported?: string[]; | ||
idTokenEncryptionEncValuesSupported?: string[]; | ||
userinfoSigningAlgValuesSupported?: string[]; | ||
userinfoEncryptionAlgValuesSupported?: string[]; | ||
userinfoEncryptionEncValuesSupported?: string[]; | ||
requestObjectSigningAlgValuesSupported?: string[]; | ||
requestObjectEncryptionAlgValuesSupported?: string[]; | ||
requestObjectEncryptionEncValuesSupported?: string[]; | ||
tokenEndpointAuthMethodsSupported?: string[]; | ||
tokenEndpointAuthSigningAlgValuesSupported?: string[]; | ||
displayValuesSupported?: string[]; | ||
claimTypesSupported?: string[]; | ||
claimsSupported: string[]; | ||
serviceDocumentation?: string[]; | ||
claimsLocalesSupported?: boolean; | ||
uiLocalesSupported?: boolean; | ||
claimsParameterSupported?: boolean; | ||
requestParameterSupported?: boolean; | ||
requestUriParameterSupported?: boolean; | ||
requireRequestUriRegistration?: boolean; | ||
opPolicyUri?: URL; | ||
opTosUri?: URL; | ||
} | ||
|
||
export interface IClient { | ||
clientId: string; | ||
clientSecret?: string; | ||
clientName?: string; | ||
} | ||
|
||
export interface IClientRegistrarOptions { | ||
sessionId: string; | ||
clientName?: string; | ||
redirectUrl?: URL; | ||
registrationAccessToken?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/oidc-dpop-client-browser/src/dpop/keyGeneration.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2020 Inrupt Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to use, | ||
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the | ||
* Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
import { describe, it } from "@jest/globals"; | ||
|
||
import { | ||
generateJwk, | ||
generateJwkForDpop, | ||
generateJwkRsa, | ||
} from "./keyGeneration"; | ||
|
||
describe("generateJwk", () => { | ||
it("can generate a RSA-based JWK", async () => { | ||
const key = await generateJwk("RSA"); | ||
expect(key.kty).toEqual("RSA"); | ||
}); | ||
|
||
it("can generate an elliptic curve-based JWK", async () => { | ||
const key = await generateJwk("EC", "P-256"); | ||
expect(key.kty).toEqual("EC"); | ||
}); | ||
}); | ||
|
||
describe("generateJwkForDpop", () => { | ||
it("generates an elliptic curve-base key, which is a sensible default for DPoP", async () => { | ||
const key = await generateJwkForDpop(); | ||
expect(key.kty).toEqual("EC"); | ||
}); | ||
}); | ||
|
||
describe("generateJwkRsa", () => { | ||
it("generates an RSA key", async () => { | ||
const key = await generateJwkRsa(); | ||
expect(key.kty).toEqual("RSA"); | ||
}); | ||
}); |
53 changes: 53 additions & 0 deletions
53
packages/oidc-dpop-client-browser/src/dpop/keyGeneration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2020 Inrupt Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to use, | ||
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the | ||
* Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
import { JWK } from "node-jose"; | ||
import { BasicParameters, ECCurve, JSONWebKey, OKPCurve } from "jose"; | ||
|
||
/** | ||
* Generates a Json Web Key | ||
* @param kty Key type | ||
* @param crvBitlength Curve length (only relevant for elliptic curve algorithms) | ||
* @param parameters | ||
* @hidden | ||
*/ | ||
export async function generateJwk( | ||
kty: "EC" | "RSA", | ||
crvBitlength?: ECCurve | OKPCurve | number, | ||
parameters?: BasicParameters | ||
): Promise<JSONWebKey> { | ||
const key = await JWK.createKey(kty, crvBitlength, parameters); | ||
return key.toJSON(true) as JSONWebKey; | ||
} | ||
|
||
/** | ||
* Generates a JSON Web Key suitable to be used to sign HTTP request headers. | ||
*/ | ||
export async function generateJwkForDpop(): Promise<JSONWebKey> { | ||
return generateJwk("EC", "P-256", { alg: "ES256" }); | ||
} | ||
|
||
/** | ||
* Generates a JSON Web Key based on the RSA algorithm | ||
*/ | ||
export async function generateJwkRsa(): Promise<JSONWebKey> { | ||
return generateJwk("RSA"); | ||
} |
Oops, something went wrong.