Authenticating against the Umbraco back office remotely - UmbracoAuthorizedApiController
Hi peeps,
After a bit of advice on trying to achieve something I've not done before.
I want to create an UmbracoAuthorizedApiController for connecting to the back office. However this API will be called from an external system so I was wondering the following:
How can I go about logging/authenticating against the back office and then call another authorizedApi?
Pointers/advice/examples to look at would be greatly appreciated :-)
The following works for me in a console application using HttpClient:
using Newtonsoft.Json;
using System;
using System.Net.Http;
using System.Text;
namespace ConsoleApplication
{
class Program
{
class LoginRequest
{
public string Username { get; set; }
public string Password { get; set; }
}
static void Main(string[] args)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:1337/umbraco/backoffice/");
var loginRequest = new LoginRequest { Username = "admin", Password = "framework123!" };
var loginRequestJson = JsonConvert.SerializeObject(loginRequest);
var content = new StringContent(loginRequestJson, Encoding.UTF8, "application/json");
var loginResult = client.PostAsync("UmbracoApi/Authentication/PostLogin", content).Result;
var testResult = client.GetAsync("Api/MyBackofficeApi/Test").Result;
Console.WriteLine(testResult.Content.ReadAsStringAsync().Result);
Console.ReadLine();
}
}
}
}
Authenticating against the Umbraco back office remotely - UmbracoAuthorizedApiController
Hi peeps,
After a bit of advice on trying to achieve something I've not done before. I want to create an UmbracoAuthorizedApiController for connecting to the back office. However this API will be called from an external system so I was wondering the following:
How can I go about logging/authenticating against the back office and then call another authorizedApi?
Pointers/advice/examples to look at would be greatly appreciated :-)
Thanks very much :-)
Nik
Hi Nik,
The following works for me in a console application using
HttpClient
:Steven
Good example.
I have a custom UsersController : UmbracoAuthorizedController, any clue how to call that ?
is working on a reply...