Eshoponcontainers: Swagger Auth Failing

Created on 21 Apr 2018  路  30Comments  路  Source: dotnet-architecture/eShopOnContainers

Hi there,

Auth is working fine through the MVC app, can login and view catalog and marketing.

When trying to auth through the Swagger UI on the marketing, location or ordering API's I get
Sorry, there was an error : unauthorized_client

In swagger I select the 'Authorize' button and in the popup I leave all at default and submit but get the error. Even If I check the scopes button I get the error?

What am I doing wrong?

Windows 10,
Docker CE 18.03.0
VS 2017 15.7.0 Preview 4

Thanks

bug

Most helpful comment

Hi @darnoldi, I was having the same problem.

I think I found the cause, a quick fix and why @VladislavAntonyuk doesn't have the same problem.

Checking the logs I got to this suspect:
image

So I checked the code and that value is set in Identity.Api/Configuration/Config.cs:
image

But changing the code there didn't fix the problem, so looking at the database I got to this table:
image
And setting the attempted value there did the trick!

This is definitely a bug, with just a quick fix (at least in my case), please let us know if this works for you.

@VladislavAntonyuk I'm guessing you didn't have this problem because you probably haven't recreated the SQL Server container for some time so you might have the proper values in that table. Could you please confirm?

We have to dig around a little to check what's the correct value for the redirection, because it might have changed now that we are using the API Gateway.

@eiximenis could you please take a look at this?

All 30 comments

you have to paste your token in swagger auth modal window

you have to paste your token in swagger auth modal window

Thanks, doesn't clicking authorize in swagger go to the authserver and request a token?

swagger1
swagger2
swagger3
If I click the authorize button in swagger (image 1), the window is pre-polulated with values which I think should request the token from the auth server (image 2). but accepting those values and clicking authorize again gives me the error message in (image 3)

Thanks for your help

you paste incorrect client_id

you paste incorrect client_id

I'm not pasting any id, that is the one that is pre-populated. Which should I use?

Thanks

You have to pass you client id which is stored in DB

The client ids are created in Identity/config.cs aren't they?

` new Client
{
ClientId = "marketingswaggerui",
ClientName = "Marketing Swagger UI",
AllowedGrantTypes = GrantTypes.Implicit,
AllowAccessTokensViaBrowser = true,

                RedirectUris = { $"{clientsUrl["MarketingApi"]}/swagger/o2c.html" },
                PostLogoutRedirectUris = { $"{clientsUrl["MarketingApi"]}/swagger/" },

                AllowedScopes =
                {
                    "marketing"
                }
            },`

you have to pass your user client id

Ok so if I understand you, I should log in using the user/password in the MVC app. Go to the database, get the token and then paste that into the swagger request?

If so, please could you show me in swagger where I can paste it?

Thanks again

after you create your user you get client id and after that you can authorize with it

I do not see anywhere in swagger where I can paste the token.
swagger4

in authorize modal window in client id

Ok I think I am understanding you more or less, which field in the database has the clientid I need to paste?

I don't remember exactly but it should be in Users table with Primary key.

The value in the Id column for the user?
00c9b2d8-d707-4f51-a0ab-6b96ed419417?

swagger5

seems like yes

no, in table Clients

This one?
swagger8

marketingswaggerui ?

yes

Thats the one that it has been using since the beginning
swagger2

I get the error with that one

I have check, there is no error for me. please switch to master and check does the problem reproduce

I will do thanks

I'm getting the same error unfortunately on master.

Before I try on another machine to check environment issues, please tell me:
If I load servicesandwebapps solution, wait for all downloads, Press F5, wait for build and containers and database seed population.
MVC app starts. I do not login anywhere.
I go to http://localhost:5110/swagger/ and click authorize, I leave all setting in modal as they are and click authorize again.
What should I see then?

Thanks for all the help

the page is updated and you have autorized

Ok thanks,

I will try a PC with a fresh install of windows and let you know

make sure you have correctly started all services and they are heathy

I have checked, they are all good, but will keep that in mind.

I am getting the exact same thing on another machine with a clean install of windows 10,

I must be misunderstanding something.

Hi @darnoldi, I was having the same problem.

I think I found the cause, a quick fix and why @VladislavAntonyuk doesn't have the same problem.

Checking the logs I got to this suspect:
image

So I checked the code and that value is set in Identity.Api/Configuration/Config.cs:
image

But changing the code there didn't fix the problem, so looking at the database I got to this table:
image
And setting the attempted value there did the trick!

This is definitely a bug, with just a quick fix (at least in my case), please let us know if this works for you.

@VladislavAntonyuk I'm guessing you didn't have this problem because you probably haven't recreated the SQL Server container for some time so you might have the proper values in that table. Could you please confirm?

We have to dig around a little to check what's the correct value for the redirection, because it might have changed now that we are using the API Gateway.

@eiximenis could you please take a look at this?

I'll check, but I suspect the error is due to a new version of Swashbuckle having a new version of Swagger UI with this new callback url.

And setting the attempted value there did the trick!

Confirmed that changing the value in the database solves the problem for me too.

I appreciate your taking the time to investigate this further, I was seriously starting to question my own sanity 8-)

Dave

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chhotalamansukh picture chhotalamansukh  路  4Comments

nxtx picture nxtx  路  4Comments

adahhane picture adahhane  路  4Comments

CESARDELATORRE picture CESARDELATORRE  路  3Comments

Mardoxx picture Mardoxx  路  3Comments