Skip to content

generic api

Jean-Marc Prieur edited this page May 3, 2023 · 6 revisions

Generic API

Scenario

  • You have a web API written in any language
  • Your web API receives a token and wants to validate it, and call downstream web APIs
  • Instead of doing it yourself, your web API will call a service (another web API) that will handle all this for you web API.

This article explains how you can implement such a service, using Microsoft.Identity.Web 2.x

Generic service

Appsettings.json

The appsettings.json has several sections.

  • The "AzureAd" section is usual. It contains the ClientId of your web API, and the client credentials for your wwb API.
  • The next section, "DownstreamApis", describes the downstream APIs that you want to call:
    • the name of the service
    • and the parameters describing this service to call. The parameters are of type: DownstreamApiOptions. Among the parameters you'll provide, you'll have the URI of the API to call, the scopes, and all the parameters that are needed for the service to authenticate
{
  "AzureAd": {
    "Instance": "https://login.microsoftonline.com/",
    "TenantId": "22222222-2222-2222-2222-222222222222",
    "ClientId": "11111111-1111-1111-11111111111111111",
    "ClientCredentials": [
      {
      }
    ],
    "Scopes": "access_as_user",
   },

  "DownstreamApis": {
    "Api1": {
      "BaseUrl": "URL",
      "Scopes": "SCOPES"
    },
    "Api2": {
      "BaseUrl": "https://graph.microsoft.com/v1.0",
      "Scopes": "user.read"
    }
  },

  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*"
}

Getting started with Microsoft Identity Web

Token cache serialization

Web apps

Web APIs

Daemon scenario

Advanced topics

Extensibility

Credential providers

FAQ

News

Contribute

Other resources

Clone this wiki locally