Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fetch an entity configuration #5

Merged
merged 1 commit into from
Jul 10, 2024

Conversation

berendsliedrecht
Copy link
Member

@berendsliedrecht berendsliedrecht commented Jul 9, 2024

  • Still needs testing

@berendsliedrecht berendsliedrecht force-pushed the fetch-entity-configuration branch 2 times, most recently from 03080bb to 06a468a Compare July 10, 2024 11:46
Copy link
Member

@TimoGlastra TimoGlastra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if we can get the error handling right with this library. That keeps being quite hard to do, with having error codes so you can handle the different error types in your application.

Any thoughts on that?


/**
*
* @todo define extact scheme
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @todo define extact scheme
* @todo define exact scheme

Comment on lines 27 to 31
const { claims, header } = jsonWebTokenSchema({
claimsSchema: entityConfigurationClaimsSchema,
headerSchema: entityConfigurationHeaderSchema,
}).parse(entityConfigurationJwt)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't a entityConfigurationJwtSchema variable make sense here? Then it can be reused as well

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah they can be combined.

// TODO: create byte array of the JWT that has to be verified
const toBeVerified = new Uint8Array()

const isValid = await verifyJwtCallback(toBeVerified, key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably add a try catch as often in callbacks errors are thrown and it would be good ti handle that.

Also -- should we make the callback props an object? It's easier to extend over time without breaking changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not too opposed to making it an object, but if we extend the object vs function params we will have the same amount of breaking changes.

Add a required prop to an object vs function param == breaking change
add an optional prop to an object vs function param == no breaking change

I do prefer it as there are two inputs of the same type so the ordering can be messed up there.

@@ -0,0 +1,134 @@
import assert from 'node:assert'
import {} from 'node:crypto'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import {} from 'node:crypto'

* @todo make get/post use the same method private internally as changes with apply to both
*
*/
const post = async ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

being able to optionally provide a custom fetch instance may be nice?

E.g. with Paradym we limit the domains/IPs that can be called with our fetch implementation, to prevent untrusted urls calling internal services.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that is the idea. But I have not thought of a way, yet, to do this properly. We can go the x509/crypto way (fetchEntityConfiguration(...normalParams, fetch? = global.fetch)` but I am not sure, yet.

import type { SignCallback, VerifyCallback } from '../src/utils'

import assert from 'node:assert/strict'
import nock from 'nock'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had issues with nock in Paradym when using native node fetch, so I moved to msw which works quite well. If you're not experiencing these issues, nock is fine with me, as the API is nice 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nock beta supports the native fetch! If I encounter errors with it I'll swap it.

@berendsliedrecht
Copy link
Member Author

It would be great if we can get the error handling right with this library. That keeps being quite hard to do, with having error codes so you can handle the different error types in your application.

Any thoughts on that?

Yes, I would like to revisit that when the first alpha version is finished.

Signed-off-by: Berend Sliedrecht <sliedrecht@berend.io>
@berendsliedrecht berendsliedrecht merged commit 12a0add into main Jul 10, 2024
2 checks passed
@berendsliedrecht berendsliedrecht deleted the fetch-entity-configuration branch July 10, 2024 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants