These pages are WIP as we transition, update, and publish more documentation.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

This getting started guide is assumes a VB/C# .NET client environment, but is helpful for any development. Some of the helper libraries will not be available, and the work will need to be manually.

The first thing you will need is a client Id and a client password, which you can request from the IIM team.


An example from the token server provider can be found here: https://identityserver4.readthedocs.io/en/release/quickstarts/1_client_credentials.html#creating-the-client

  1. You want to install the IdentityModel package from the NuGet feed into your client project.
  2. This will enable you to shortcut some of the URL mapping and discovery in the OAuth workflow. The following will do this work for you

    Discovery of IDs Metadata
    // discover endpoints from metadata
    var disco = await DiscoveryClient.GetAsync("https://warden.data.uwaterloo.ca");
    if (disco.IsError)
    {
        Console.WriteLine(disco.Error);
        return;
    }
  3. Next you'll pass your credentials to the token server and receive back a JSON response that will include your authorization token.

    Getting Token from IdentityServer
    var tokenClient = new TokenClient(disco.TokenEndpoint, "your_client_id", "your_client_password");
    var tokenResponse = await tokenClient.RequestClientCredentialsAsync("sourceapi");
    
    if (tokenResponse.IsError)
    {
        Console.WriteLine(tokenResponse.Error);
        return;
    }
    
    Console.WriteLine(tokenResponse.Json);
  4. Now with your valid token you'll be able to make calls against the API to get data.
  5. To send the access token to the API you typically use the HTTP Authorization header. This is done using the SetBearerToken extension method.

    Calling the API with Token
    var client = new HttpClient();
    client.SetBearerToken(tokenResponse.AccessToken);
    
    var response = await client.GetAsync("https://api.data.uwaterloo.ca/v1/terms");
    if (!response.IsSuccessStatusCode)
    {
        Console.WriteLine(response.StatusCode);
    }
    else
    {
        var content = await response.Content.ReadAsStringAsync();
        Console.WriteLine(content);
    }
  • No labels