void Initialize(string defaultDomain, string ptrCtrAppId, string ptrCtrAppSecret, string resellerMicrosoftId) { // Get Active Directory token first adAuthorizationToken = Reseller.GetAD_Token(defaultDomain, ptrCtrAppId, ptrCtrAppSecret); // Using the ADToken get the sales agent token saAuthorizationToken = Reseller.GetSA_Token(adAuthorizationToken); // Get the Reseller Cid, you can cache this value resellerCid = Reseller.GetCid(resellerMicrosoftId, saAuthorizationToken.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 AzureTokenResponse 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 CSPTokenResponse 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 CSPTokenResponse 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 AzureTokenResponse adToken = GetADToken(domain, clientId, clientSecret); adAuthorizationToken = new AuthorizationToken(adToken.access_token, Convert.ToInt64(adToken.expires_in)); } return adAuthorizationToken; }