iayti / CleanArchitecture

ASP.NET Core 6 Web API Clean Architecture Solution Template
MIT License
654 stars 120 forks source link

DenyAnonymousAuthorizationRequirement: Requires an authenticated user #26

Closed asheroto closed 3 years ago

asheroto commented 3 years ago

This probably isn't a bug, just me not understanding .NET 5 + AspNetCore libraries, so I didn't click Bug Report just yet.

I followed the steps on the README but when trying it out through Swagger (the URL that pops up) it doesn't seem to authenticate. I tried using Super_Secret_Key as the token to authorize but got this...

image

and in console, the message that's in the subject of this issue.

Sorry, I'm still learning the AspNetCore libraries. Thanks for being patient with me. I have a lot of webapp experience and .NET Framework but haven't made my way into the .NET 5 API world until now.

I did get it working if I use Client.WorkerService... is it just the Swagger script that isn't working?

I tried through Postman with the same response. How would one authenticate through an API key?

Can you guide me to the right spot to add authorized tokens, or if it's just one token like Super_Secret_Key let me know what I'm doing wrong.

Thank you very much!

iayti commented 3 years ago

I intend to detail the wikis of the project. README is not clear enough about this. Thank you for informing me. You can generate new tokens with Swagger Login endpoint.

Default User Email: test@test.com Password: Matech_1850

If you want to change or remove the default user credentials, check the Infrastructure.Persistence => ApplicationDbContextSeed

image

To run Endpoints via swagger, we need to add the token information you created with the Authorize button in swagger page.

image

Authorize Token usage sample: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6ImMyMTQxNmM4LTYyMzAtNDQ4Yy1hZjZjLWI0Y2M4NTFmNzQ4YSIsImp0aSI6ImM4M2Q1YTM4LWFhZjEtNGNjNS05ZDE2LWJhOTA2MjRiNzBlMSIsImV4cCI6MTYyMDIyMjY1MywiaXNzIjoiVmFsaWRJc3N1ZXIiLCJhdWQiOiJWYWxpZEF1ZGllbmNlIn0.nTrpDcCe6H2clg2BBl-XwqIITJylnFfdr33ldhqOKbg

You can copy the sample token above and use it directly. There is one more topic that is not explained on README, I think I add it to the wiki. Installing all platforms and MSSQL database settings with Docker.

Have a nice coding 😊

asheroto commented 3 years ago

Ah! Thank you very much!

I am on GitHub daily to find, comment, write, and contribute. I'll fork your repo and help contribute to it, including the README.