Resource Owner Flow Authorization Example

This examples below provide code for getting an access token using the Resource Owner flow.

Prerequisites

Code Examples

C#

using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace HotDocsAdvanceApiExamples
{
    public class ResourceOwnerAuthorization
        {
        public static async Task<string> GetResourceOwnerTokenAsync()
        {
            using var client = new HttpClient();
            var request = new HttpRequestMessage
            {
                RequestUri = new Uri("https://yourtenancy.yourorganization.com/HdaAuth/Authorize/ServicePrincipalLogIn"),
                Method = HttpMethod.Post,
                Content = JsonContent.Create(new
                {
                    ClientName = "ab3e4544-b595-4681-b0ea-c7c18c9b63f6",
                    PrincipalName = "ExampleServicePrincipalA",
                    PrincipalPassword = "examplePassword"
                })
            };
            var response = await client.SendAsync(request);
            response.EnsureSuccessStatusCode();
            return await response.Content.ReadAsStringAsync();
        }
    }
}

Powershell

$body = @{
    ClientName = "ExampleClientA"
    PrincipalName = "ExampleServicePrincipalA"
    PrincipalPassword = "examplePassword"
} | ConvertTo-Json
$header = @{
 "Accept"="application/json"
 "Content-Type"="application/json"
} $result = Invoke-RestMethod -Uri "https://yourtenancy.hotdocsadvance.com/Auth/Authorize/ServicePrincipalLogIn" -Method 'Post' -Body $body -Headers $header
Write-Host $result