Go to file
Frede Hundewadt 3089f6c8b7 update
2023-10-13 09:27:26 +02:00
Properties refactor for other project 2023-10-03 09:09:26 +02:00
.gitignore Initial commit 2022-12-14 11:57:22 +01:00
app.config update 2023-10-13 09:27:26 +02:00
AzureAuthStore.cs refactor for other project 2023-10-03 09:09:26 +02:00
AzureConfigStore.cs refactor for other project 2023-10-03 09:09:26 +02:00
AzureToken.cs refactor for other project 2023-10-03 09:09:26 +02:00
AzureTokenDto.cs refactor for other project 2023-10-03 09:09:26 +02:00
AzureTokenFetcher.cs refactor for other project 2023-10-03 09:09:26 +02:00
AzureTokenHttpRequest.cs refactor for other project 2023-10-03 09:09:26 +02:00
AzureTokenMapper.cs refactor for other project 2023-10-03 09:09:26 +02:00
FCS.Lib.Azure.csproj update 2023-10-13 09:27:26 +02:00
IAzureConfigProvider.cs refactor for other project 2023-10-03 09:09:26 +02:00
IAzureTokenFetcher.cs refactor for other project 2023-10-03 09:09:26 +02:00
IAzureTokenProvider.cs refactor for other project 2023-10-03 09:09:26 +02:00
LICENSE Initial commit 2022-12-14 11:57:22 +01:00
packages.config initial commit 2022-12-14 12:01:50 +01:00
README.md Update README.md 2022-12-24 07:38:31 +01:00

fcs-azure

Library to aquire Azure access token

Sample call

using System;
using FCS.Lib.Azure;
using FCS.Lib.Utility;

namespace TestAzure
{
    public class Program
    {
        static void Main(string[] args)
        {
            var settings = new MySettings();

            var authStore = new AzureAuthStore(
                settings.LoginUrl, settings.OAuthEndpoint, settings.LoginScope, settings.GrantType, 
                settings.TenantId, settings.ClientId, settings.ClientSecret);

            var tokenFetcher = new AzureTokenFetcher(authStore);

            // normally called async - but this is only a test
            var token = tokenFetcher.FetchAzureToken().Result;

            var ts1 = Mogrify.CurrentDateTimeToTimeStamp();
            var ts2 = Mogrify.DateTimeToTimeStamp(DateTime.Now.AddHours(+2));

            Console.WriteLine($"AccessToken: {token.AccessToken}");
            Console.WriteLine($"Expires    : {token.Expires}");
            Console.WriteLine($"TokenType  : {token.TokenType}");
            Console.WriteLine($"HasExpired : {DateTime.Now} {token.HasExpired(ts1)}");
            Console.WriteLine($"HasExpired : {DateTime.Now.AddHours(+2)} {token.HasExpired(ts2)}");
            Console.ReadKey();
        }
    }

    internal sealed class MySettings
    {
        public string LoginUrl => "https://login.microsoftonline.com";
        public string OAuthEndpoint => "oauth2/v2.0/token";
        public string GrantType => "client_credentials";
        public string LoginScope => "insert-your-login-scope";
        public string TenantId => "insert-your-tenant-id";
        public string ClientId => "insert-your-client-id";
        public string ClientSecret => "insert-your-client-secret";
    }
}