/// <summary> /// Get the token for authenticating requests to Azure Resource Manager in customer tenant. /// </summary> /// <param name="appId">appid that is registered for this application in Azure Active Directory (AAD)</param> /// <param name="credentialName">Internet or network address of entry in Credential Manager (Windows Credentials / Generic Credential) </param> /// <param name="customerTenantId">cid of the customer</param> /// <param name="azureAuthToken">Existing token (if available)</param> /// <returns>Azure Auth Token in the context of the customer tenant.</returns> public static string GetAzureAuthTokenForCustomerTenant(string appId, string credentialName, string customerTenantId, AuthorizationToken azureAuthToken = null) { if (azureAuthToken == null || (azureAuthToken != null && azureAuthToken.IsNearExpiry())) { //// Refresh the token on one of two conditions //// 1. If the token has never been retrieved //// 2. If the token is near expiry var azToken = GetAzureAuthTokenForCustomerTenant(appId, credentialName, customerTenantId); azureAuthToken = new AuthorizationToken(azToken.AccessToken, azToken.ExpiresOn); } return azureAuthToken.AccessToken; }
/// <summary> /// Get the latest AD token given the reseller domain and client credentials /// </summary> /// <param name="domain">domain of the reseller</param> /// <param name="clientId">clientID of the application</param> /// <param name="clientSecret">client secret of the application, also refered to as key</param> /// <param name="adAuthorizationToken">ad authorization token, can be null</param> /// <returns>Latest AD Authorization token</returns> public static AuthorizationToken GetAD_Token(string domain, string clientId, string clientSecret, AuthorizationToken adAuthorizationToken = null) { if (adAuthorizationToken == null || (adAuthorizationToken != null && adAuthorizationToken.IsNearExpiry())) { //// Refresh the token on one of two conditions //// 1. If the token has never been retrieved //// 2. If the token is near expiry var adToken = GetADToken(domain, clientId, clientSecret); adAuthorizationToken = new AuthorizationToken(adToken.access_token, Convert.ToInt64(adToken.expires_in)); } return(adAuthorizationToken); }
/// <summary> /// Get the token for authenticating requests to Azure Resource Manager in customer tenant. /// </summary> /// <param name="appId">appid that is registered for this application in Azure Active Directory (AAD)</param> /// <param name="credentialName">Internet or network address of entry in Credential Manager (Windows Credentials / Generic Credential) </param> /// <param name="customerTenantId">cid of the customer</param> /// <param name="azureAuthToken">Existing token (if available)</param> /// <returns>Azure Auth Token in the context of the customer tenant.</returns> public static string GetAzureAuthTokenForCustomerTenant(string appId, string credentialName, string customerTenantId, AuthorizationToken azureAuthToken = null) { if (azureAuthToken == null || (azureAuthToken != null && azureAuthToken.IsNearExpiry())) { //// Refresh the token on one of two conditions //// 1. If the token has never been retrieved //// 2. If the token is near expiry var azToken = GetAzureAuthTokenForCustomerTenant(appId, credentialName, customerTenantId); azureAuthToken = new AuthorizationToken(azToken.AccessToken, azToken.ExpiresOn); } return(azureAuthToken.AccessToken); }
/// <summary> /// Get the latest AD token given the reseller domain and client credentials /// </summary> /// <param name="domain">domain of the reseller</param> /// <param name="clientId">clientID of the application</param> /// <param name="clientSecret">client secret of the application, also refered to as key</param> /// <param name="adAuthorizationToken">ad authorization token, can be null</param> /// <returns>Latest AD Authorization token</returns> public static AuthorizationToken GetAD_Token(string domain, string clientId, string clientSecret, AuthorizationToken adAuthorizationToken = null) { if (adAuthorizationToken == null || (adAuthorizationToken != null && adAuthorizationToken.IsNearExpiry())) { //// Refresh the token on one of two conditions //// 1. If the token has never been retrieved //// 2. If the token is near expiry var adToken = GetADToken(domain, clientId, clientSecret); adAuthorizationToken = new AuthorizationToken(adToken.access_token, Convert.ToInt64(adToken.expires_in)); } return adAuthorizationToken; }
/// <summary> /// Get the latest sales agent token given the AD Authorization Token /// </summary> /// <param name="adAuthorizationToken">AD Authorization Token</param> /// <param name="saAuthorizationToken">Sales agent authorization token, can be null</param> /// <returns>Latest sales agent token</returns> public static AuthorizationToken GetSA_Token(AuthorizationToken adAuthorizationToken, AuthorizationToken saAuthorizationToken = null) { if (saAuthorizationToken == null || (saAuthorizationToken != null && saAuthorizationToken.IsNearExpiry())) { //// Refresh the token on one of two conditions //// 1. If the token has never been retrieved //// 2. If the token is near expiry var saToken = GetSA_Token(adAuthorizationToken.AccessToken); saAuthorizationToken = new AuthorizationToken(saToken.access_token, Convert.ToInt64(saToken.expires_in)); } return(saAuthorizationToken); }
/// <summary> /// Get the latest sales agent token given the AD Authorization Token /// </summary> /// <param name="adAuthorizationToken">AD Authorization Token</param> /// <param name="saAuthorizationToken">Sales agent authorization token, can be null</param> /// <returns>Latest sales agent token</returns> public static AuthorizationToken GetSA_Token(AuthorizationToken adAuthorizationToken, AuthorizationToken saAuthorizationToken = null) { if (saAuthorizationToken == null || (saAuthorizationToken != null && saAuthorizationToken.IsNearExpiry())) { //// Refresh the token on one of two conditions //// 1. If the token has never been retrieved //// 2. If the token is near expiry var saToken = GetSA_Token(adAuthorizationToken.AccessToken); saAuthorizationToken = new AuthorizationToken(saToken.access_token, Convert.ToInt64(saToken.expires_in)); } return saAuthorizationToken; }
/// <summary> /// Get the latest AD token given the reseller domain and client credentials /// </summary> /// <param name="domain">domain of the reseller</param> /// <param name="clientId">clientID of the application</param> /// <param name="clientSecret">client secret of the application, also refered to as key</param> /// <param name="adAuthorizationToken">ad authorization token, can be null</param> /// <returns>Latest AD Authorization token</returns> public static AuthorizationToken GetAD_Token(string domain, string clientId, string clientSecret, AuthorizationToken adAuthorizationToken = null) { if (adAuthorizationToken == null || (adAuthorizationToken != null && adAuthorizationToken.IsNearExpiry())) { //// Refresh the token on one of two conditions //// 1. If the token has never been retrieved //// 2. If the token is near expiry //var adToken = GetADToken(domain, clientId, clientSecret); //adAuthorizationToken = new AuthorizationToken(adToken.access_token, Convert.ToInt64(adToken.expires_in)); // MOCK API simulates tokens var adToken = Json.Decode("{\"access_token\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ijd3YzlFTnVyWGZaRWt5VkxfZkM5cTZpeHNMRSJ9.eyJpc3MiOiJ1cm46Y3BzdHMiLCJhdWQiOiJ1cm46Y3BzdmM6Y2E6ODZmZDM1YjktMzhhMi00MTNjLWE5YjEtMzNiYjc1ZjNiZDRmIiwibmJmIjoxNDM4MzY5OTIyLCJleHAiOjE0MzgzNzA4MjIsIm5hbWVpZCI6IjkwNDg1QTVFLUQyRTMtNDU5RC04NzFFLUM1OTVBQzhBMEUzNiIsInVuaXF1ZV9uYW1lIjoiVGh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ZEhsQmNIQWlMQ0poY0hCcFpDSTZJalJpTTJSaFpEbGpMV1UxTVRZdE5EYzJaaTA1WmpreUxUSmtOemxrWVRsbVkySmpaaUlzSWtsa1pXNTBhV1pwWlhKSlpDSTZJamcyWm1Rek5XSTVMVE00WVRJdE5ERXpZeTFoT1dJeExUTXpZbUkzTldZelltUTBaaUlzSW5KdmJHVWlPaUpCWTNSUGJsSmxjMlZzYkdWeVEyaGhibTVsYkNKOS4ifQ.GHg0RLBo-rdX4CINR6N54rL5m741df4QWh_aRyQW2gIbtqpOHZlJ-3CYBHtgy-rcfMFXia2N1BppBFZ4rGLuqRtyyStUDbWMoMVyMU2LwXyUyNVtiEg5K7YY9KaZLqzEgMxe5VM9HLwC0evM6yyjXiFABr7mTJe4OOpJcPXDAvh2DKjA5reqf4y9HODth1GLpN0bsNNTcGzeOP2rsEsEwMIaUeP0mBE60fVQ3lR5yt1_gZlUObi_CIC_nAnW3l5Je1JtWsYzq4AlLhnGrfsywi5V2TQLp6Wo6w0x6btZNBEExOryS691flzL6Cyr_PUXKSH0_-rgEu_s3zWvSZJoqw\",\"token_type\":\"bearer\",\"expires_in\":900}"); adAuthorizationToken = new AuthorizationToken(adToken.access_token, Convert.ToInt64(adToken.expires_in)); } return(adAuthorizationToken); }
/// <summary> /// This method is used to get the customer token given a customer cid and the ad token /// </summary> /// <param name="customerCid">cid of the customer</param> /// <param name="adAuthorizationToken">active directory authorization token</param> /// <param name="customerAuthorizationToken">customer authorization token if available</param> /// <returns>customer authorization token</returns> public static AuthorizationToken GetCustomer_Token(string customerCid, AuthorizationToken adAuthorizationToken, AuthorizationToken customerAuthorizationToken = null) { if (customerAuthorizationToken == null || (customerAuthorizationToken != null && customerAuthorizationToken.IsNearExpiry())) { //// Refresh the token on one of two conditions //// 1. If the token has never been retrieved //// 2. If the token is near expiry var customerToken = GetCustomer_Token(customerCid, adAuthorizationToken.AccessToken); customerAuthorizationToken = new AuthorizationToken(customerToken.access_token, Convert.ToInt64(customerToken.expires_in)); } return(customerAuthorizationToken); }
/// <summary> /// Get the latest AD token given the reseller domain and client credentials /// </summary> /// <param name="domain">domain of the reseller</param> /// <param name="clientId">clientID of the application</param> /// <param name="clientSecret">client secret of the application, also refered to as key</param> /// <param name="adAuthorizationToken">ad authorization token, can be null</param> /// <returns>Latest AD Authorization token</returns> public static AuthorizationToken GetAD_Token(string domain, string clientId, string clientSecret, AuthorizationToken adAuthorizationToken = null) { if (adAuthorizationToken == null || (adAuthorizationToken != null && adAuthorizationToken.IsNearExpiry())) { //// Refresh the token on one of two conditions //// 1. If the token has never been retrieved //// 2. If the token is near expiry //var adToken = GetADToken(domain, clientId, clientSecret); //adAuthorizationToken = new AuthorizationToken(adToken.access_token, Convert.ToInt64(adToken.expires_in)); // MOCK API simulates tokens var adToken = Json.Decode("{\"access_token\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ijd3YzlFTnVyWGZaRWt5VkxfZkM5cTZpeHNMRSJ9.eyJpc3MiOiJ1cm46Y3BzdHMiLCJhdWQiOiJ1cm46Y3BzdmM6Y2E6ODZmZDM1YjktMzhhMi00MTNjLWE5YjEtMzNiYjc1ZjNiZDRmIiwibmJmIjoxNDM4MzY5OTIyLCJleHAiOjE0MzgzNzA4MjIsIm5hbWVpZCI6IjkwNDg1QTVFLUQyRTMtNDU5RC04NzFFLUM1OTVBQzhBMEUzNiIsInVuaXF1ZV9uYW1lIjoiVGhpcmRQYXJ0eUFwcCIsIklkZW50aWZpZXJJZCI6Ijg2ZmQzNWI5LTM4YTItNDEzYy1hOWIxLTMzYmI3NWYzYmQ0ZiIsImFwcGlkIjoiNGIzZGFkOWMtZTUxNi00NzZmLTlmOTItMmQ3OWRhOWZjYmNmIiwiQ2FpZCI6Ijg2ZmQzNWI5LTM4YTItNDEzYy1hOWIxLTMzYmI3NWYzYmQ0ZiIsIklzVGVzdCI6IlRydWUiLCJyb2xlIjoiU2FsZXNBZ2VudCIsImFjdG9ydCI6ImV5S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btqpOHZlJ-3CYBHtgy-rcfMFXia2N1BppBFZ4rGLuqRtyyStUDbWMoMVyMU2LwXyUyNVtiEg5K7YY9KaZLqzEgMxe5VM9HLwC0evM6yyjXiFABr7mTJe4OOpJcPXDAvh2DKjA5reqf4y9HODth1GLpN0bsNNTcGzeOP2rsEsEwMIaUeP0mBE60fVQ3lR5yt1_gZlUObi_CIC_nAnW3l5Je1JtWsYzq4AlLhnGrfsywi5V2TQLp6Wo6w0x6btZNBEExOryS691flzL6Cyr_PUXKSH0_-rgEu_s3zWvSZJoqw\",\"token_type\":\"bearer\",\"expires_in\":900}"); adAuthorizationToken = new AuthorizationToken(adToken.access_token, Convert.ToInt64(adToken.expires_in)); } return adAuthorizationToken; }
/// <summary> /// Get the latest partner center api token given the AD Authorization Token /// </summary> /// <param name="adAuthorizationToken">AD Authorization Token</param> /// <param name="clientId">clientID of the application</param> /// <param name="partnerCenterApiAuthorizationToken">partner center api authorization token, can be null</param> /// <returns>Latest partner center api authorization token</returns> public static AuthorizationToken GetPartnerCenterApi_Token(AuthorizationToken adAuthorizationToken, string clientId, AuthorizationToken partnerCenterApiAuthorizationToken = null) { if (partnerCenterApiAuthorizationToken == null || (partnerCenterApiAuthorizationToken != null && partnerCenterApiAuthorizationToken.IsNearExpiry()) ) { //// Refresh the token on one of two conditions //// 1. If the token has never been retrieved //// 2. If the token is near expiry var partnerCenterApiToken = GetPartnerCenterApi_Token(adAuthorizationToken.AccessToken, clientId); var accessToken = partnerCenterApiToken.access_token.ToString(); var expiresInOffset = System.Convert.ToInt64(partnerCenterApiToken.expires_in); partnerCenterApiAuthorizationToken = new AuthorizationToken(accessToken, expiresInOffset); } return(partnerCenterApiAuthorizationToken); }
/// <summary> /// This method is used to get the customer token given a customer cid and the ad token /// </summary> /// <param name="customerCid">cid of the customer</param> /// <param name="adAuthorizationToken">active directory authorization token</param> /// <param name="customerAuthorizationToken">customer authorization token if available</param> /// <returns>customer authorization token</returns> public static AuthorizationToken GetCustomer_Token(string customerCid, AuthorizationToken adAuthorizationToken, AuthorizationToken customerAuthorizationToken = null) { if (customerAuthorizationToken == null || (customerAuthorizationToken != null && customerAuthorizationToken.IsNearExpiry())) { //// Refresh the token on one of two conditions //// 1. If the token has never been retrieved //// 2. If the token is near expiry var customerToken = GetCustomer_Token(customerCid, adAuthorizationToken.AccessToken); customerAuthorizationToken = new AuthorizationToken(customerToken.access_token, Convert.ToInt64(customerToken.expires_in)); } return customerAuthorizationToken; }