NAME
Azure::AD::ClientCredentialsV2 - Azure AD Client Credentials authentication flow
SYNOPSIS
use Azure::AD::ClientCredentialsV2;
my $creds = Azure::AD::ClientCredentialsV2->new(
resource_id => 'https://management.core.windows.net/',
client_id => '',
secret_id => '',
tenant_id => '',
);
say $creds->access_token;
DESCRIPTION
Implements the Azure AD Client Credentials flow using the V2 Oauth endpoint. See Azure::AD::Auth for more information and alternative flows.
ATTRIBUTES
scope
Defines the set of permissions being requested by the application. Scopes can be either static (using .default) or dynamic. This set can include the OpenID Connect scopes (openid, profile, email). If you need application permissions, you must use .default to request the statically configured list of permissions.
tenant_id
The ID of the Azure Active Directory Tenant that you want to request permission from. It can be provided in a GUID or friendly name format.
client_id
The Client ID (also referred to as the Application ID) of an application
secret_id
A Key assigned to the Client Id.
ad_url
This defaults to https://login.microsoftonline.com
, and generally doesn't need to be specified. Azure AD has more endpoints for some clouds:
https://login.chinacloudapi.cn
China Cloud
https://login.microsoftonline.us
US Gov Cloud
https://login.microsoftonline.de
German Cloud
METHODS
access_token
Returns the access token that has to be sent to the APIs you want to access. This is normally sent in the Authentication header of HTTPS requests as a Bearer token.
The access_token is cached in the object as long as it's valid, so subsequent calls to access_token will return the appropiate token without reauthenticating to Azure AD. If the token has expired, access_token will call Azure AD to obtain a new token transparently.
Example usage:
my $auth = Azure::AD::ClientCredentialsV2->new(...);
use HTTP::Tiny;
my $ua = HTTP::Tiny->new;
my $response = $ua->get(
'http://aservice.com/orders/list',
{
headers => { Authorization => 'Bearer ' . $auth->access_token }
}
);
SEE ALSO
COPYRIGHT and LICENSE
Copyright (c) 2020 by Jose Luis Martinez
This code is distributed under the Apache 2 License. The full text of the license can be found in the LICENSE file included with this module.