No description
Find a file
2022-12-14 12:01:50 +01:00
Properties initial commit 2022-12-14 12:01:50 +01:00
.gitignore Initial commit 2022-12-14 11:57:22 +01:00
app.config initial commit 2022-12-14 12:01:50 +01:00
AzureAuthStore.cs initial commit 2022-12-14 12:01:50 +01:00
AzureToken.cs initial commit 2022-12-14 12:01:50 +01:00
AzureTokenDto.cs initial commit 2022-12-14 12:01:50 +01:00
AzureTokenFetcher.cs initial commit 2022-12-14 12:01:50 +01:00
AzureTokenHttpRequest.cs initial commit 2022-12-14 12:01:50 +01:00
AzureTokenMapper.cs initial commit 2022-12-14 12:01:50 +01:00
FCS.Lib.Azure.csproj initial commit 2022-12-14 12:01:50 +01:00
IAzureTokenFetcher.cs initial commit 2022-12-14 12:01:50 +01: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 initial commit 2022-12-14 12:01:50 +01:00
ResponseView.cs initial commit 2022-12-14 12:01:50 +01:00

fcs-azure

Library to aquire Azure access token

Sample call

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

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

        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} {ts1} {token.HasExpired(ts1)}");
        Console.WriteLine($"HasExpired : {DateTime.Now.AddHours(+2)} {ts2} {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 => "";
    public string TenantId => "";
    public string ClientId => "";
    public string ClientSecret => "";
}