title | description | author | ms.localizationpriority | ms.subservice | doc_type |
---|---|---|---|---|---|
Assign tokenLifetimePolicy |
Assign a tokenLifetimePolicy to a service principal. |
sureshja |
medium |
entra-applications |
apiPageType |
Namespace: microsoft.graph
Assign a tokenLifetimePolicy to a servicePrincipal. You can have multiple tokenLifetimePolicy policies in a tenant but can assign only one tokenLifetimePolicy per service principal.
One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions.
Permission type | Permissions (from least to most privileged) |
---|---|
Delegated (work or school account) | Policy.Read.All and Application.ReadWrite.All, Policy.ReadWrite.ApplicationConfiguration and Application.ReadWrite.All |
Delegated (personal Microsoft account) | Not supported. |
Application | Policy.Read.All and Application.ReadWrite.OwnedBy, Policy.Read.All and Application.ReadWrite.All, Policy.ReadWrite.ApplicationConfiguration and Application.ReadWrite.OwnedBy, Policy.ReadWrite.ApplicationConfiguration and Application.ReadWrite.All |
You can address the service principal using either its id or appId. id and appId are referred to as the Object ID and Application (Client) ID, respectively, in enterprise applications in the Microsoft Entra admin center.
POST /servicePrincipals/{id}/tokenLifetimePolicies/$ref
POST /servicePrincipals(appId='{appId}')/tokenLifetimePolicies/$ref
Name | Description |
---|---|
Authorization | Bearer {token}. Required. Learn more about authentication and authorization. |
Content-Type | application/json. Required. |
In the request body, supply the identifier of the tokenLifetimePolicy object (using an @odata.id
property) that should be assigned to the application or service principal.
If successful, this method returns a 204 No Content
response code.
The following example shows a request.
POST https://graph.microsoft.com/v1.0/servicePrincipals/2a8f9e7a-af01-413a-9592-c32ec0e5c1a7/tokenLifetimePolicies/$ref
Content-Type: application/json
{
"@odata.id": "https://graph.microsoft.com/v1.0/policies/tokenLifetimePolicies/4d2f137b-e8a9-46da-a5c3-cc85b2b840a4"
}
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
The following example shows the response.
HTTP/1.1 204 No Content