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

Allow access_token as url query parameter for authentication #2

Closed
dev7ch opened this issue Jan 31, 2024 · 4 comments
Closed

Allow access_token as url query parameter for authentication #2

dev7ch opened this issue Jan 31, 2024 · 4 comments

Comments

@dev7ch
Copy link

dev7ch commented Jan 31, 2024

Hi @johind
Thanks for publishing this module.

I would like to ask if this is also supposed to work with static access_token as query param in URL?

As i see for now (without digging) access_token does not throw an error on your app but i still get an Unauthorized as response.

@johind
Copy link
Owner

johind commented Jan 31, 2024

Hey, thanks for showing interest in it!

I have tested it with a static_token using both the Authorization header Bearer <token> and adding ?access_token=<token> to the url, both worked fine for me.

Does the user your static token belongs to have the necessary permissions for the data you are trying to use? And did you change the code so that it fits your data models?

@dev7ch
Copy link
Author

dev7ch commented Feb 1, 2024

mmh, permission should be fine (tested with admin user as well)

And did you change the code so that it fits your data models?

What do you mean with that? do i have to extend the files model or at some other places?

image

@johind
Copy link
Owner

johind commented Feb 1, 2024

Hey, what i meant with that is that the endpoint expects a data model called footage to exist

const footageService = new ItemsService("footage", { schema });

and this then also expects a one-to-many relation between footage and the scenes data model, like here:

const footage = (await footageService.readOne(primaryKey, {
	fields: ["scenes.index", "scenes.footage_in", "scenes.footage_out", "file.metadata"],
	deep: { scenes: { _sort: ["index"] } },
})) as Footage;

This requests the footage item by id with related scenes data included.

I hard coded these data models because it kinda was just a proof-of-concept and not a ready to use extension :D

So this Unauthorized Error might come from one of these two data models not defined. I just tested this by renaming footages to something else and it indeed returned an Unauthorized error.

Let me know if this helped! So the solution would be to edit the code in the extension so that it fits the data models that you have in your directus instance and then to re-build the extension. It currently needs the following information:

type Scene = { 
    index: number; 
    footage_in: number; 
    footage_out: number 
};
type Footage = { 
    scenes: Scene[]; 
    file: { 
        metadata: { 
            frame_rate: number 
        } 
    } 
};

index is just a helper for the correct order of the scenes
footage_in is the start_frame of the scene relative to the video
footage_out is the end_frame of the scene

and in my case i added a frame_rate to the metadata object of a directus file. if you edit the code you might aswell save the frame_rate with a data model instead. for me it made sense to save it to the directus file on creation.

@dev7ch
Copy link
Author

dev7ch commented Feb 5, 2024

ah thanks a lot, yes this helped, after a closer look and your explanation it is working.

@dev7ch dev7ch closed this as completed Feb 5, 2024
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

No branches or pull requests

2 participants