I have a case where I need some controller methods to be accessible either by an authenticated user, or if the request contains a sort of "acccess token" in the url.
For example:
Either an authenticated user could make a call to:
https://example.com/some/resource
Or a non authenticated user could make the same call, but add some kind of token to the url (or as a header):
https://example.com/some/resource?token=123abc
The token does not have to be super secret, only something hard to guess.
[AllowSpecialToken]
[HttpGet]
[Route("some/resource")]
public async Task<string> GetSomeResource()
{
return "some resource";
}
What I'm struggling with is how to write the AllowSpecialTokenAttribute
. And how to get that to run before the authentication (using OpenIddict
) we have in place now.
Is this a stupid use case? Should I find another solution?
To give some context: We have a SPA that calls our API. Some pages of the SPA can be shared with others (non user) just by sending a link. That link will contain the token. The content of those pages are not critical security wise, but they shouldn't be completely open.