2

Dears,

I've followed https://stormpath.com/blog/token-authentication-asp-net-core to authenticate the user for my web apis I managed to create a successful access-token when calling api/token

My problem is the use of [Authorize], authorize filter didn't get that my user has a valid token, although HeaderAuthorization and HeaderExpries have been set.

function getValues()
{
    $.ajax({
        url: "http://localhost:48146/api/values",
        headers: { 'Authorization': 'Basic ' + accessToken, Expires: tokenExpires },
        method: "GET",
        context: document.body,
        success: function (data) {
            alert(data);
        }
    });
}

Did I passed a wrong header?

2 Answers 2

2

Based on the tutorial you followed you should pass a bearer authorization header, not a basic authorization header:

headers: { 'Authorization': 'bearer' + accessToken, Expires: tokenExpires },

Sign up to request clarification or add additional context in comments.

Comments

0

I've figured out 2 problems

  1. as @user1336 said in header I had theaders: { 'Authorization': 'bearer' + accessToken, Expires: tokenExpires },
  2. I had to call ConfigureAuth(app) before app.UseMvc(); in Startup.css

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.