Administration

Gold-Vision API

Creating the client using IdentityModel

The token endpoint implements the OAuth 2.0 protocol, and you could use raw HTTP to access it.  However, a client library called IdentityModel is available, that encapsulates the protocol interaction in an easy to use API. Add the IdentityModel NuGet package to your client. This can be done either via Visual Studio’s Nuget Package manager or though the package manager Console with the following command: Install-Package IdentityModel or by using the CLI: dotnet add package IdentityModel IdentityModel includes a client library to use with the discovery endpoint. This way you only need to know the base-address of the server – the actual endpoint addresses can be read from the metadata:
// discover endpoints from metadata
var client = new HttpClient();
var disco = await client.GetDiscoveryDocumentAsync("https://uk.gold-vision.me/connect/token");
if (disco.IsError)
{
    Console.WriteLine(disco.Error);
    return;
}
Next you can use the information from the discovery document to request a token to access goldvisionapi:
// request token
var tokenResponse = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
{
    Address = disco.TokenEndpoint,

    ClientId = "client",
    ClientSecret = "secret",
    Scope = "goldvisionapi"
});

if (tokenResponse.IsError)
{
    Console.WriteLine(tokenResponse.Error);
    return;
}

Console.WriteLine(tokenResponse.Json);


Was this article helpful?

Thank you for your feedback