Native console application quickstart

In this article

    A quick-start guide for getting you up and running with a native console application.

    Before you begin

    • you have a tenant with a user for testing sign-on
    • you have registered your application with the following options:
      • OpenID Connect native app flow


      • redirect URI of ^\:\d{4,10}/desktop-callback$

    • you have received a unique application client ID and secret 
    • you have Visual Studio (community, professional, or enterprise edition)


    1. Clone or download the SuperOffice.DevNet.OpenIDConnectNativeApp from GitHub.

      git clone​

    2. In Visual Studio, go to the Source directory and open the SuperOffice.DevNet.OpenIDConnectNativeApp.sln file.

    3. Under the Build menu, click Build Solution, or press the F6 key on the keyboard, to restore NuGet packages and build the solution file.

    4. From the Debug menu,  click Start Debugging, or press the F5 key.

      Observe that the application runs and opens a console window.


    5. Press any key. The default browser window opens to the SuperOffice sign-in page.


    6. At this point, if you have multiple tenants, a list of available tenants appear. Choose a tenant to grant access to your application.

    7. If this is the 1st time accessing this tenant via this application, a consent dialog appears asking for application approval to gain access to your web service resources.

      Click I approve.

    8. The browser callback is shown and eventually navigates to the SuperOffice community web site.

      This default behavior is defined in the console application code.

    9. The console application continues and dumps the contents of the response, including the id_token, claims and access_token.


    Next steps

    At this point, you probably want to use access_token to send a request to the tenant's web services. The sample application uses the full .Net framework and you would, therefore, use the WebRequest class to send a request to the server to obtain data from the tenant. 

    The following code represents a basic method to issue a GET request that is later used to call the tenant web services.

    private static string GetData(string uri, string tokenType, string accessToken)
        HttpWebRequest httpWebRequest = WebRequest.CreateHttp(uri);
        httpWebRequest.Method = "GET";
        httpWebRequest.Accept = "application/json";
        httpWebRequest.Headers.Add(HttpRequestHeader.Authorization, string.Concat(tokenType, " ", accessToken));
        var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
        using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            var responseText = streamReader.ReadToEnd();
            return responseText;

    The 1st thing needed is the web service URL. In this case, I extract the base webapi_url (REST) and the current user's associateId from the claims.

    // result is the LoginResult provided by the OidcClient library used earlier in this sample
    var webApiUrl = result.User.Claims.Where(c => c.Type.Contains("webapi_url")).Select(n => n.Value).FirstOrDefault();
    var associateid = result.User.Claims.Where(c => c.Type.Contains("associateid")).Select(n => n.Value).FirstOrDefault();

    Build up the search URL using a combination of the webApiUrl and the web service version URI to invoke an OData query against an archive provider search. 

    // search the tenant for the companyId and personId of the logged in associate
    // build up the OData query to perform a search using the InternalUsers archive provider
    var uri = $"v1/Archive/InternalUsers?$entities=all&$select=contactId,personId&$filter=associateDbId eq {associateid}";
    var queryResult = GetData(string.Concat(webApiUrl, uri), "Bearer", result.AccessToken);

    Search results

      "odata.metadata": "$metadata",
      "odata.nextLink": null,
      "value": [
          "PrimaryKey": "5",
          "EntityName": "all",
          "personId": 5,
          "contactId": 2