/// <summary> /// Obtains an authorization token for the specified resource. /// </summary> /// <param name="resource"> /// The resource for which to obtain an authorization token. /// </param> /// <returns> /// The authorization token. /// </returns> internal static string ObtainAuthorizationToken(string resource) { string result; // Build the fully qualified resource name. string environment = String.Concat("commerce-", CommerceWorkerConfig.Instance.Environment); string fullyQualifiedResource = String.Format("https://{0}.TODO_INSERT_YOUR_DOMAIN_HERE/api/commerce/service/{1}", environment, resource); // If the token has already been retrieved and is still valid, use it. if (Tokens.ContainsKey(fullyQualifiedResource) == true && Tokens[fullyQualifiedResource].Received + TokenLifetime > DateTime.Now) { result = Tokens[fullyQualifiedResource].Token; } // Otherwise, obtain and store a new token. else { ISimpleWebTokenRequestor requestor = PartnerFactory.SimpleWebTokenRequestor(); result = requestor.RequestToken("Orchestrated Job Queue", CommerceWorkerConfig.Instance.AcsClientCredential, environment, fullyQualifiedResource); Tokens[fullyQualifiedResource] = new SimpleWebToken { Token = result, Received = DateTime.Now }; } return(result); }