Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nik 1299 posts 5501 karma points MVP 3x c-trib
    Feb 23, 2017 @ 14:55
    Nik
    0

    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

  • Steven Harland 78 posts 497 karma points c-trib
    Feb 27, 2017 @ 18:57
    Steven Harland
    0

    Hi Nik,

    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();
                }
            }
        }
    }
    

    Steven

  • Biagio Paruolo 1492 posts 1633 karma points c-trib
    Jun 16, 2017 @ 05:45
    Biagio Paruolo
    0

    Good example.

  • Tajamal 64 posts 152 karma points
    Feb 17, 2020 @ 20:00
    Tajamal
    0

    I have a custom UsersController : UmbracoAuthorizedController, any clue how to call that ?

Please Sign in or register to post replies

Write your reply to:

Draft