401 Not Authorized Litium Admin Web API

Litium version: 7.4.0

I’m getting 401 Not authorized when trying to Authorize with a token created from code.

I want to be able to access the Litium Web API with a token for the currently logged in user.

I used this code to create the token:

var currentPersonId = _securityContextService.GetIdentityUserSystemId();
                return null;

            var person = _personService.Get(currentPersonId.Value);
            if (person == null)
                return null;

            var identity = _securityContextService.CreateClaimsIdentity(person.LoginCredential.Username, person.SystemId);
            var properties = new AuthenticationProperties
                IssuedUtc = DateTime.UtcNow,
                ExpiresUtc = DateTime.UtcNow.Add(new TimeSpan(10,0,0)),

            return OAuthServiceExtensions.OAuthBearerOptions.AccessTokenFormat.Protect(new AuthenticationTicket(identity, properties));

When logged in in Litium as an admin I get back the token like:


In the front-end I try to get all campaigns from the admin API using this token as a bearer in the header:

:authority: local.mysite.com
:method: POST
:path: /Litium/api/admin/sales/campaigns/search
:scheme: https
accept: */*
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.9
authorization: bearer FbLIbvnRTiOBu4nbXDMt2lDlKc3ADOt4vZr0CZlg1yCRflUcn0vo53S0QIVYRoihpAwSm5c5MDWctHF9q8upi6xBEbCSd0nWuUvTGwYNXbFKGLgJcGM8uYmXGyHQPVBL1weJJM7BfQypk7WRY0EoX9NXjciF0n7UHuHh_YUWiZsR0Ee6_ARSTU0h_A5bkEtorggJqFKt32OhMzH5JIBfW9mhNjBD45uuyZvqzANSepnLGVy09uGHhFdaPJNXdvqhy0xKgVe_mPgTxiDN_2GRCWaTst5Io0KeYFM1MCYLE5l4cUKtICPxI6NttKrslimvGGVKjHDvIrgHQs-T5Px3HKO0v1mvsg1qGy1oobjlT9jV7u3LTGfUeVsgb3Y50G8Q
cache-control: no-cache

I still get a 401 back.

cache-control: no-store, must-revalidate, no-cache, max-age=0
content-length: 0
date: Tue, 30 Jun 2020 07:56:47 GMT
server: Microsoft-IIS/10.0
status: 401
www-authenticate: ServiceAccount
www-authenticate: Bearer
x-correlation-id: 4af6968f-333f-4c69-bea2-daeebd458a76
x-powered-by: ASP.NET

I can’t figure out what is wrong. How can I use the current logged in user to fetch data from the admin API?

Did you create a Service account user?

No, I want to use the credentials for the currently logged in user.

Litium Admin Web API require that you authenticate with a service account.

Ok I see, :frowning: I’m building a panel and looking for a way to authorize the currently logged in user against the admin API. Is there any preferred way to do this? How does Litium use the API’s in the GUI?

It’s not possible to use the current logged in user with the admin Web API. The Web API that Litium administration interface is using other endpoints that have different needs.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.