Hello Sir
I would like you to help on WEB API.
I was trying to get the Users from the link below [http://aspnetzero.com/Documents/Development-Guide#token-based-authentication])
but i am getting following error
{
"success": false,
"result": null,
"error": {
"code": 0,
"message": "No user logged in!",
"details": null,
"validationErrors": null
},
"unAuthorizedRequest": true
}
I have already authenticated users in your previous steps and copied that authorization as well
I have added three attachments for your perusal as well.
2 Answer(s)
-
0
Hi Hassan,
You should set Authorization as "Bearer {{token}}". Since they are not secrets, can you share your screenshots without hiding these.
This token based auth is well tested and working. I just created a demo on aspnetzero.com and used Postman to test it:
Authentication:
POST /api/Account/Authenticate HTTP/1.1 Host: halilapitest.demo.aspnetzero.com Content-Type: application/json Cache-Control: no-cache Postman-Token: a2c36490-c2a7-696c-09f5-6247a73f321b { tenancyName: 'halilapitest', usernameOrEmailAddress: 'admin', password: "123456" }
And this is jQuery of same request:
var settings = { "async": true, "crossDomain": true, "url": "http://halilapitest.demo.aspnetzero.com/api/Account/Authenticate", "method": "POST", "headers": { "content-type": "application/json", "cache-control": "no-cache", "postman-token": "fc8fdbb7-b81d-46e8-1a57-2ee485375488" }, "data": "{\n tenancyName: 'halilapitest',\n usernameOrEmailAddress: 'admin',\n password: \"123456\"\n}" } $.ajax(settings).done(function (response) { console.log(response); });
Request to get users:
POST /api/services/app/user/getUsers HTTP/1.1 Host: halilapitest.demo.aspnetzero.com Content-Type: application/json Authorization: Bearer mhU93JU3wiIcXwvLlLK5gqhQtkYhfEs_e1JZSFQQiP3ZkOau2KWwUenrPApLg4bZbuZ3-Y-ENa1WsEAev_R9nZYy0KfUtLfPEwJg8pzjrLWgzYC1RqQkicwky5LTN4uj1zUiGjgovNYza4yJP7APjaJeFVUeyA8F-HprwEVRYigUN8zQ3LpBsRdT3JN8_nmj_NlqpLzpBCgRHnlbL1EDKjDnm3118_tUUIfSDVV2hYqEt9VI2TX4SXpI2OJobG_7OpHiUCwTsn1K4H6UA8hJJOm6s_RNHAkA86rLzwiOy7shrONoCzOabC_s4uKm9r79vwjznAPl8JOwN6akuGetSE1M1p-qsaT1A1bMqpE7ddLZ1MvFrM11FMxx3XaER-erP-kpmTmK0MpXR5H_FAxwV3cLOCmtl8KhYuprMHOlICSd1elzHHah_A1Mo4WUKg0rRZTzdrCrUzHd_lPNRWh4TQ Cache-Control: no-cache Postman-Token: 9db00619-a020-8f6d-9ae3-c6ff662eb283 {}
And the jQuery code:
var settings = { "async": true, "crossDomain": true, "url": "http://halilapitest.demo.aspnetzero.com/api/services/app/user/getUsers", "method": "POST", "headers": { "content-type": "application/json", "authorization": "Bearer mhU93JU3wiIcXwvLlLK5gqhQtkYhfEs_e1JZSFQQiP3ZkOau2KWwUenrPApLg4bZbuZ3-Y-ENa1WsEAev_R9nZYy0KfUtLfPEwJg8pzjrLWgzYC1RqQkicwky5LTN4uj1zUiGjgovNYza4yJP7APjaJeFVUeyA8F-HprwEVRYigUN8zQ3LpBsRdT3JN8_nmj_NlqpLzpBCgRHnlbL1EDKjDnm3118_tUUIfSDVV2hYqEt9VI2TX4SXpI2OJobG_7OpHiUCwTsn1K4H6UA8hJJOm6s_RNHAkA86rLzwiOy7shrONoCzOabC_s4uKm9r79vwjznAPl8JOwN6akuGetSE1M1p-qsaT1A1bMqpE7ddLZ1MvFrM11FMxx3XaER-erP-kpmTmK0MpXR5H_FAxwV3cLOCmtl8KhYuprMHOlICSd1elzHHah_A1Mo4WUKg0rRZTzdrCrUzHd_lPNRWh4TQ", "cache-control": "no-cache", "postman-token": "835cd178-f5b3-be8a-dee4-5263b5dc6332" }, "processData": false, "data": "{}" } $.ajax(settings).done(function (response) { console.log(response); });
Please check your parameters.
-
0
Thanks Much
it works perfectly
and i forgot to set the bearer there in the request