0

I need to authenticate the user on the backend using the authentication cookie I have stored. I need to request API in Vue using axios requests and send cookie in those requests. The user should then be authenticated in the backend controller. I store the cookie as a whole:

public string GetOrchardAuthCookie()
{
    return new ChunkingCookieManager().GetRequestCookie(_httpContextAccessor.HttpContext, "orchauth_Default");
}

my axios request:

axios.get(apiUrl, {
        headers: {
            "orchauth_Default": mySavedCookie
        }
    })
        .then(response =>
        {
            this.categories = response;
        })
        .catch(this.errorHandle);

after the request is made and I stop the code in the controller, the user has 0 claims

How to make Axios request to authenticate User in asp .net core controller?

2
  • Could this case answer your question?stackoverflow.com/questions/52549079/… Commented May 16, 2022 at 8:11
  • @RuikaiFeng I have my Orchauth_Default cookie saved in html input element. I need to retrieve it inside widget and send it in api requests. My backend api then should automatically autenticate user. withCredentials: true has nothing to do with this, you cannot add cookie with this solution. Maybe i just do not understand correctly, feel free to explain. :) Commented May 19, 2022 at 7:16

1 Answer 1

1

I found a solution. The cookie had to be passed to Axios as follows:

axios.defaults.headers.common['orchauth_Default'] = mySavedCookie;

my OrchardCore backend will now automatically authenticate users in the api controller

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

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.