Community
Showing results for 
Search instead for 
Do you mean 
Reply

POST api/Contacts - Test API - Authentication Required

Accepted Solution Solved
Copper Contributor
Posts: 42
Country: United States
Accepted Solution

POST api/Contacts - Test API - Authentication Required

I'm just starting out learning Web API.  I'm only dimly familiar with JSON.  I got the bearer token.  I looked at the POST api/Contacts sample and clicked Test API.  I put the bearer token into the Authorization header, click Send Request, and a dialog pops up, stating the server http://localhost requires a username and password.  I assume that's not supposed to happen, and nothing I type in makes it stop from popping right back up again.

 

I already ran the installer: do I need to do any additional configuration?  Am I perhaps missing something for the Authentication header?


Accepted Solutions
Solution
Accepted by topic author bconner26
‎01-18-2016 12:48 PM
Employee
Posts: 236
Country: USA

Re: POST api/Contacts - Test API - Authentication Required

If you are using .../Act.Web.API/Help that means the Web API was installed correctly, so you are good there.  

 

Are you including the database name?  It's case sensitive, and often a reason for authentication here to go wrong.  Also, make sure you can log in normally to that database.  Log into .../APFW with the same credentials you are trying.  Sometimes people have a pending user, or don't have the user they think they do in that database, etc..

 

Hope that helps.

 

 

View solution in original post


All Replies
Solution
Accepted by topic author bconner26
‎01-18-2016 12:48 PM
Employee
Posts: 236
Country: USA

Re: POST api/Contacts - Test API - Authentication Required

If you are using .../Act.Web.API/Help that means the Web API was installed correctly, so you are good there.  

 

Are you including the database name?  It's case sensitive, and often a reason for authentication here to go wrong.  Also, make sure you can log in normally to that database.  Log into .../APFW with the same credentials you are trying.  Sometimes people have a pending user, or don't have the user they think they do in that database, etc..

 

Hope that helps.

 

 

Copper Contributor
Posts: 42
Country: United States

Re: POST api/Contacts - Test API - Authentication Required

I guess the token expired, or I made a typo with the last one?  I had it generate a new one and now it's working.

 

Thanks.

Employee
Posts: 236
Country: USA

Re: POST api/Contacts - Test API - Authentication Required

Good to hear.  Keep in mind tokens expire every hour, so it will expire again Smiley Happy

New Member
Posts: 6
Country: Poland

Re: POST api/Contacts - Test API - Authentication Required

[ Edited ]

@Xavier, what did you mean when you said: Keep in mind tokens expire every hour, so it will expire again. 

Does the token expire exactly 60 minutes after it was fetched or every next hour (10:00, 11:00, 12:00)?

I made some research here and I noticed that each next authorization request returns the same token if token did not expire yet.
That makes imposible to fetch new token ahead of expiration time. 
Is there any way to check by API request when token exactly expire?

Employee
Posts: 236
Country: USA

Re: POST api/Contacts - Test API - Authentication Required

Tokens are effectively only valid for an hour.  So when you receive a valid token, you will not be able to use that same token after an hour.  If you trade in your token for a new one (via /authorize), you will receive a new token.  You will never receive the same token.  If you want to check the expiration time, a token is a signed Json Web Token (JWT), you would need to use a library, or simply base64 decode the token and view and parse the payload section for the issue timestamp.  As a failsafe, if you receive a 401 from the API using a token, you know it's time to refresh it.

New Member
Posts: 6
Country: Poland

Re: POST api/Contacts - Test API - Authentication Required

Thanks for details here Smiley Happy.