Service to Service Authentication (2024)

  • Article

Microsoft Community Training APIs support Service to Service (S2S) authentication to allow any external service to call the APIs without requiring a user to explicitly login to any MCT instance.

Please follow the following steps to enable any external service to call Microsoft Community Training APIs:

Step 1: Register Service Application

Follow the steps mentioned below to Register the Service app.Register the service app:

  1. Sign in to the Azure portal.

  2. If you have access to multiple tenants, use the Directory + subscription filter Service to Service Authentication (1) in the top menu to select the tenant in which you want to register an application.

    Note

    The Service Application to be registered must be created in the same Azure tenant as that of concerned MCT instance.

  3. Search for and select Azure Active Directory.

  4. Under Manage, select App registrations > New registration.

  5. When the Register an application page appears, enter your application's registration information:

    • In the Name section, enter a meaningful application name that will be displayed to users of the app (e.g. MCT service).
    • Leave Supported account types on the default setting of Accounts in this organizational directory only.
  6. Select Register to create the application.

  7. Select the Expose an API section, and:

    • On Application ID URI, click on Set. Keep the suggested value, for example api://webapi-clientid
    • Click SaveService to Service Authentication (2)
  8. Select the Manifest section, and:

    • Edit the manifest by locating the “appRoles”.
    • The role definition is provided in the JSON code snippet below.
    • Enter “allowedMemberTypes” to “Application”.
    • Enter your appRoles “displayName” (e.g. "S2SAppRole" used as displayName for the below code snippet)
    • Each role definition in this manifest must have a different valid Guid for the "id" property.
    • To create a unique Guid run the command “new-guid” from PowerShell.
    • Enter the role “value” as created in “Register Service application” step above. (e.g. "S2SAppRole")
    • Map the respective values properly and save the manifest.

Note

The content of appRoles should be the following (the id should be unique Guid)

{… "appRoles": [ { "allowedMemberTypes": [ "Application" ], "description": "Apps in this role can consume the web api.", "displayName": "S2SAppRole", "id": "Your guid created above", "isEnabled": true, "lang": null, "origin": "Application", "value": "S2SAppRole" } ],...}

Save the following values to be used later:

  • Tenant ID – Copy the TenantID from the ActiveDirectory overview page.
  • Tenant Name – Similarly copy the TenantName from overview page.(e.g. {anyName}.onmicrosoft.com)

The Overview page looks like:

Service to Service Authentication (3)

Application ID URI – Copy the value from the overview page of registered application after completing “Expose an API” step as mentioned above (e.g. api://<webapi-clientid>)

The overview page of registered application looks like:

Service to Service Authentication (4)

Value – (e.g., S2SAppRole) Role that was created while editing the manifest in the above steps.

Step 2: Register Client Application(s)

For each of the applications which would call the Microsoft Community Training API’s, follow the steps under Approach 1 or Approach 2 below based on the type of application which would call the APIs.

Approach 1: If the API calling service is hosted in Azure (List of the services)

Steps mentioned below are for Azure function, similar steps can be followed for other services.

  1. Follow the steps mentioned in this document to Create a new Azure Function App.
  2. Go the function app created above and click on the “Identity” section on the left.
    1. Switch the status to “on”. Click on “Save”

    2. Copy the value of “Object Id” shown on the screen thereafter. It will be required later.

      Service to Service Authentication (5)

    3. Follow the steps mentioned in this document to generate a token to call the APIs. A resource parameter is required to generate the token. For this parameter, provide the value of the Application ID URI as created in “Register Service application” step. (e.g. api://{Id})

Note

Any coding language can be used based on the runtime stack selected while creating the Function App.

Approach 2: Alternatively, creating a client by using Client Credentials Flow

Follow the steps mentioned below to Register the Client app.

  1. Sign in to the Azure portal.
  2. If you have access to multiple tenants, use the Directory + subscription filter Service to Service Authentication (6) in the top menu to select the tenant in which you want to register an application.
  3. Search for and select Azure Active Directory.
  4. Under Manage, select App registrations > New registration.
    • In the Name section, enter a meaningful application name that will be displayed to users of the app, for example S2S-client.
    • In the Supported account types section, select Accounts in this organizational directory only ({tenant name}).
    • Select Register to create the application.
  5. On the app Overview page, find the Application (client) ID value and record it for later.
  6. From the Certificates & secrets page, in the Client secrets section, choose New client secret:
    • Type a key description (of instance app secret),
    • Select a key duration of either In 1 year, In 2 years, or Never Expires.
    • When you press the Add button, the key value will be displayed, copy, and save the value in a safe location.
    • You'll need this key later to configure the project in Visual Studio. This key value will not be displayed again, nor retrievable by any other means, so record it as soon as it is visible from the Azure portal.
  7. In the list of pages for the app, select API permissions.
    • Click the Add a permission button and then,
    • Ensure that the My APIs tab is selected.
    • Select the API created in the previous step (e.g. MCT service created in the “Register Service application” step).
    • In the Application permissions section, ensure that the right permissions are checked (e.g. S2SAppRole created in “Register Service application” step)
    • Select the Add permissions button.
  8. At this stage permissions are assigned correctly but the client app does not allow interaction. Therefore, no consent can be presented via a UI and accepted to use the service app. Click the Grant/revoke admin consent for {tenant} button, and then select Yes when you are asked if you want to grant consent for the requested permissions for all account in the tenant. You need to be an Azure AD tenant admin to do this.

Note

  • Refer this link to generate tokens to call APIs.
POST /{tenant}/oauth2/v2.0/token HTTP/1.1 //Line breaks for clarityHost: login.microsoftonline.comContent-Type: application/x-www-form-urlencodedclient_id=<The application ID that's assigned to your app>&scope=https://graph.microsoft.com/.default&client_secret=sampleCredentials&grant_type=client_credentials
  • The value passed for the scope parameter in this request should be the resource identifier (application ID URI) of the resource you want, affixed with the .default suffix api://webapi-clientid/.default. For the Microsoft Graph example, the value is https://graph.microsoft.com/.default.

Step 3: Configure the Azure App Service

  1. Go the resource group created as part of the Microsoft Community Training deployment
  2. Under the list of resources, go the “App Service” resource

    Warning

    The name of this resource would be the same name which was provided as the Website name at the time of deployment creation.
    There is another App Service resource which is created for the function app. (The name of this resource would usually have “-fa-” in the name). This should NOT be selected.

  3. After going to the App Service resource, Click on the “Configuration” section on the left.
  4. Click on “New application setting”
  5. Under “Name”, add ServiceAuthEnabled, and under “Value”, add true. Click “OK”.Service to Service Authentication (7)
  6. Similarly add the following values in the Configuration. Click on “Save” after adding all these values and restart the App Service.
    1. ServiceAuthAudience: Application ID URI created in “Register Service application” step
    2. ServiceAuthTenantName: Tenant name retrieved in “Register Service application” step
    3. ServiceAuthTenantId: Tenant Id retrieved in “Register Service application” step
    4. ServiceObjectIds: This is required only if the Client type is of type Approach 1 above. Enter the Object Id retrieved above. If multiple clients are created of this type, enter all of them here, separated by a semi-colon. (ObjectId_1;ObjectId_2…). This is client objectId from step2-Approach1
    5. ServiceApplicationIds: This is required only if the Client type is of type Approach 2 above. Enter the Application Id retrieved above. If multiple clients are created of this type, enter all of them here, separated by a semi-colon. (ApplicationId_1;ApplicationId_2…). This is client application ID from step2-Approach2
    6. ServiceAuthRole: This is required only if the Client type is of type 2.b) Enter the role value as created in the manifest in the “Register Service application” step above. (e.g. "S2SAppRole").

Warning

While making Service auth calls, add a new header with key: ClientType and value: Service.

The client(s) created above should now be able to call the Microsoft Community Training APIs. Add the token(s) generated above to the Rest APIs exposed by the platform.

Service to Service Authentication (2024)

FAQs

How does service to service authentication work? ›

Service-to-Service (S2S) authentication is suited for scenarios where integrations are required to run without any user interaction. S2S authentication uses the Client Credentials OAuth 2.0 Flow. This flow enables you to access resources by using the identity of an application.

How do you handle authentication between microservices? ›

In a simple scenario, authorization only occurs at the edge, typically using an API Gateway. You can use an API Gateway to centralize authentication and authorization for all downstream microservices. The gateway enforces authentication and access control for each microservice.

How do I authenticate a webservice? ›

Web service clients can authenticate themselves either by using the authentication mechanisms provided by the HTTP protocol such as basic authentication, or by adding a security token to the WS Security header. Depending on the authentication mechanism, different authentication options are available.

Which service is used for authentication? ›

Lightweight Directory Access Protocol (LDAP) is used in authentication to verify credentials with a directory service. With LDAP, clients request user data stored within the database and provide access if credentials match. Password Authentication Protocol (PAP) is used if servers cannot handle stronger protocols.

How SSO works in microservices? ›

Single Sign-on in Microservices Architecture

Single sign-on (SSO) enables an entity—whether a user, system, process, service, or app—to log in to one service, application, or system and automatically gain access to other applications without needing to sign in again.

How do I pass JWT token from one microservice to another? ›

A user has to hit an endpoint ("/login") with username and password and generate a token and pass this as a RequestHeader to all end points in both the services. Say in microservice A, I have an endpoint ("test1/createSomething"). In B I have another have an endpoint ("test2/getSomething").

How do I authenticate a user in REST API? ›

  1. #1 API Key (identification only) One of the easiest ways to identify an API client is by using an API key. ...
  2. #2 OAuth2 token. OAuth2 is a comprehensive industry standard that is widely used across API providers. ...
  3. #3 External token or assertion. ...
  4. #4 Token Exchange. ...
  5. #5 Identity facade for 3 legged OAuth.
Feb 9, 2023

How do you secure a REST API and how do you authenticate it? ›

Use HTTPS/TLS for REST APIs

As one of the most critical practices, every API should implement HTTPS for integrity, confidentiality, and authenticity. In addition, security teams should consider using mutually authenticated client-side certificates that provide extra protection for sensitive data and services.

What are 4 ways to authenticate? ›

Usually, authentication by a server entails the use of a user name and password. Other ways to authenticate can be through cards, retina scans, voice recognition, and fingerprints.

How do I manage authentication in Web API? ›

If we want to check the authentication before invoking the action method then we need to use the built-in Authorize Filter Attribute. If we want any action method to be accessed by the anonymous users then we need to decorate that action method with the AllowAnonymous attribute.

What is the best authentication method for web application? ›

For web applications that leverage server-side templating, session-based auth via username and password is often the most appropriate. You can add OAuth and OpenID as well. For RESTful APIs, token-based authentication is the recommended approach since it's stateless.

What is the most commonly used form of authentication? ›

Fingerprint scanners

Fingerprints are the most popular form of biometric authentication. The system to verify users with them mainly relies on mobile native sensing technology.

What is the difference between user service and authentication service? ›

Auth would be responsible for handling tokens and also store a part of user information such related to Authentication (perhaps password, roles). User service will hold all other information such as additional addresses, avatars etc.

What is Kerberos service to service authentication? ›

Kerberos authentication is a multistep process that consists of the following components: The client who initiates the need for a service request on the user's behalf. The server, which hosts the service that the user needs access to. The AS, which performs client authentication.

How does server certificate authentication work? ›

SSL-enabled client software always requires server authentication, or cryptographic validation by a client of the server's identity. The server sends the client a certificate to authenticate itself. The client uses the certificate to authenticate the identity the certificate claims to represent.

What is service authentication? ›

An authentication service is a mechanism, analogous to the use of passwords on time-sharing systems, for the secure authentication of the identity of network clients by servers and vice versa, without presuming the operating system integrity of either (e.g., Kerberos).

Do you need authentication between microservices? ›

In a microservice architecture, developers are in the tricky position of securing not just a single external API gateway, but each individual microservice API with a secure authorization step. Indeed, a core tenet of a zero-trust architecture is that every request must be both authenticated and authorized.

Top Articles
Latest Posts
Article information

Author: Lidia Grady

Last Updated:

Views: 6352

Rating: 4.4 / 5 (65 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Lidia Grady

Birthday: 1992-01-22

Address: Suite 493 356 Dale Fall, New Wanda, RI 52485

Phone: +29914464387516

Job: Customer Engineer

Hobby: Cryptography, Writing, Dowsing, Stand-up comedy, Calligraphy, Web surfing, Ghost hunting

Introduction: My name is Lidia Grady, I am a thankful, fine, glamorous, lucky, lively, pleasant, shiny person who loves writing and wants to share my knowledge and understanding with you.