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

can not login using Swagger #3658

Closed
sajasbana opened this issue Jul 23, 2018 · 18 comments
Closed

can not login using Swagger #3658

sajasbana opened this issue Jul 23, 2018 · 18 comments

Comments

@sajasbana
Copy link

Dears
Iam using abp mvc with multi pages template, I update solution from nuget package,
everything in application is working only small issue when try swagger
-if try login from swaggerit show success login like this,
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'X-XSRF-TOKEN: nZA_eRB5T4OU6uNbzNmRY6cgoExHFbygioA5enbakT4YY2GcJHmACcuqEwmSGCdF6311dAwSMqBCNEKfnuMUKT3nMsQl_RBKgbsSGVtnHOs1' -d '{ \ "tenancyName": "", \ "usernameOrEmailAddress": "admin", \ "password": "123qwe" \ }' 'http://localhost:61814/api/Account'

{ "result": "LJZqORn3tTCF-t29W6wK5JNodT5G0pzKW8V6ylf8DKjTrlcXKMiwXfnbGEhhcjsyu4KfDtWww0GGEwsHAuU3siYvmYmjZgV0b_2YT70wPG4JK-fkkvk3LU9525u96W2H5gWm2JwiD0olOVUgsY56fZMwoS_TGE1WFfJOPK2YHF1_Xe8Fdti6Xy4rlKPJLS6q9vbbgEuteyt35yRZ_NlFz8R_lyp9Y4hgc0WYul7xn8SAtO33A-wqXSMqUuFAKIBCksy55pOqZOiqB9MyY6eNz_BUlFfLEgwzQ9wTgqT8xqbpxPj7ZI1bbL-iJzMmhfMlHqA4lBdbHWJuRlVYIJMxWK1RlZ1bvPfSdaKn2jyoEWXKThIScEdstsozwiDYiXr1EBkBm61nRvvGKxUC4PEVOfG7E4hRHjWf-0MR8hFo54zuJ1hWdzNenGpz36k_7JWsbL7Dl6cZLNdkhXVmiANkdA7YHEKsDZyUDM4P9lUMV4w", "targetUrl": null, "success": true, "error": null, "unAuthorizedRequest": false, "__abp": true }

but when try see from session api the current login user it shows null in tenant and userId
like this

{ "result": { "user": null, "tenant": null }, "targetUrl": null, "success": true, "error": null, "unAuthorizedRequest": false, "__abp": true }

Please help in this issue

@maliming
Copy link
Member

Does the request header contain "Authorization: Bearer xyz"?

@sajasbana
Copy link
Author

as you can see it is like this

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'X-XSRF-TOKEN: nZA_eRB5T4OU6uNbzNmRY6cgoExHFbygioA5enbakT4YY2GcJHmACcuqEwmSGCdF6311dAwSMqBCNEKfnuMUKT3nMsQl_RBKgbsSGVtnHOs1' -d '{ \ "tenancyName": "", \ "usernameOrEmailAddress": "admin", \ "password": "123qwe" \ }' 'http://localhost:61814/api/Account'

i dont see Authorization: Bearer xyz

how can I add it?
I download solution from templates

@ryancyq
Copy link
Contributor

ryancyq commented Jul 23, 2018

You can try the approach mentioned in #3653 (comment)

@acjh
Copy link
Contributor

acjh commented Jul 23, 2018

There's no "login from Swagger". It just calls an endpoint.

@sajasbana
Copy link
Author

@acjh
I mean Authenticate
these is my steps when using swagger:

I follwed the steps in swagger integration but it seems the is something wrong ... see images

step1
step2
step3

@maliming
Copy link
Member

@sajasbana
Does your request have an Authorization header?

image

@sajasbana
Copy link
Author

@maliming
Thank you for replay ... I just understand I have to add Authorization header as this link explain
https://aspnetboilerplate.com/Pages/Documents/Zero/Startup-Template#token-based-authentication

it will be helpful if swagger works in mvc mpa template also and be able to add Authorization header

@acjh
Copy link
Contributor

acjh commented Jul 23, 2018

I follwed the steps in swagger integration but it seems the is something wrong ... see images

That's Postman...

@sajasbana
Copy link
Author

@acjh
this is from swagger ui ... same results as postman before i add Authorization header ... but now i know how add Authorization header to postman but what about swagger ... how to fix this?

s1
s2

@acjh
Copy link
Contributor

acjh commented Jul 23, 2018

var authToken = '';
var bearerAuth = new SwaggerClient.ApiKeyAuthorization('Authorization', 'Bearer ' + authToken, 'header');
swaggerUi.api.clientAuthorizations.add('bearerAuth', bearerAuth);

@sajasbana
Copy link
Author

sajasbana commented Jul 23, 2018

@acjh
your code worked and add Authorization header but it is empty
Is there way to set the value of it? this will be very helpful
wwhen click the button

s1

@acjh
Copy link
Contributor

acjh commented Jul 23, 2018

Copy and paste from the value of "result".

@sajasbana
Copy link
Author

sajasbana commented Jul 23, 2018

Dear @acjh
I did as these images shows but it shows invalid anti-forgery... there wrong in my code

p1
p2
p3

another test

p4
p5

@acjh
Copy link
Contributor

acjh commented Jul 23, 2018

Clear your cookies.

@sajasbana
Copy link
Author

sajasbana commented Jul 23, 2018

@acjh
appreciate you valuable time
it worked now as you see, the value should be X-XSRF-TOKEN: null

d1
d2

now is there way to fill header 'Authorization: Bearer xxx' value dynamicly?

@sajasbana
Copy link
Author

@acjh
I want share my solution for this issue

please add to template for other users

share

Scripts.zip

@ryancyq
Copy link
Contributor

ryancyq commented Jul 24, 2018

@sajasbana

Didn't notice that you were referring to module-zero-template

Not sure if you have seen it. The authorize button has already added into MPA

See https://github.com/aspnetboilerplate/module-zero-core-template/blob/master/aspnet-core/src/AbpCompanyName.AbpProjectName.Web.Host/wwwroot/swagger/ui/index.html#L98

@sajasbana
Copy link
Author

@ryancyq
I talkin about this template ... there is no auth button ... it will be helpful if you add it

s1

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

4 participants