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();
if(!currentPersonId.HasValue)
{
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:
FbLIbvnRTiOBu4nbXDMt2lDlKc3ADOt4vZr0CZlg1yCRflUcn0vo53S0QIVYRoihpAwSm5c5MDWctHF9q8upi6xBEbCSd0nWuUvTGwYNXbFKGLgJcGM8uYmXGyHQPVBL1weJJM7BfQypk7WRY0EoX9NXjciF0n7UHuHh_YUWiZsR0Ee6_ARSTU0h_A5bkEtorggJqFKt32OhMzH5JIBfW9mhNjBD45uuyZvqzANSepnLGVy09uGHhFdaPJNXdvqhy0xKgVe_mPgTxiDN_2GRCWaTst5Io0KeYFM1MCYLE5l4cUKtICPxI6NttKrslimvGGVKjHDvIrgHQs-T5Px3HKO0v1mvsg1qGy1oobjlT9jV7u3LTGfUeVsgb3Y50G8Q
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?