コード例 #1
0
ファイル: ApiClient.cs プロジェクト: Xenophik/WContact
        /// <summary>
        ///   Sets the request authentication header
        /// </summary>
        /// <param name="client"> Http client</param>
        /// <param name="requestUri">request Url</param>
        /// <param name="apiKey"> battle.net api authenticate keys </param>
        internal static void SetAuthenticationHeader(HttpClient client, Uri requestUri, ApiKeyPair apiKey)
        {
            if (apiKey != null && _authenticationSupport != null)
            {
                DateTimeOffset date = DateTimeOffset.Now.ToUniversalTime();
                client.DefaultRequestHeaders.Date = date;

                string dateString = date.ToString("r", CultureInfo.InvariantCulture);

                string stringToSign = "GET" + "\n" + dateString
                                      + "\n" + requestUri.AbsolutePath + "\n";
                using (
                    var hashAlgorithm =
                        (IDisposable)
                        Activator.CreateInstance(_authenticationSupport.HashType, apiKey.GetPrivateKeyBytes()))
                {
                    string signature = Convert.ToBase64String(
                        (byte[])_authenticationSupport.ComputeHashMethod.Invoke(hashAlgorithm,
                                                                                new object[]
                    {
                        Encoding.UTF8.GetBytes(
                            stringToSign)
                    }));
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("BNET", apiKey.PublicKey + ":" + signature);
                }
            }
        }
コード例 #2
0
ファイル: ApiClient.cs プロジェクト: Xenophik/WContact
 /// <summary>
 ///   Constructor. Initializes a new instance of the ApiClient class
 /// </summary>
 /// <param name="region"> Regional battle.net Community website to which the ApiClient should connect to perform request. </param>
 /// <param name="apiKey"> Application key used to authenticate requests sent by the ApiClient </param>
 /// <param name="locale"> The locale to use to perform request (item names, class names, etc are retrieved in the locale specified) </param>
 /// <param name="cacheManager"> Cache manager to cache data </param>
 /// <remarks>
 ///   Only Locales supported by the regional website that the ApiClient is connecting to are supported. If a wrong local is passed, default language is used.
 /// </remarks>
 protected ApiClient(Region region, ApiKeyPair apiKey, string locale, ICacheManager cacheManager)
     : this(region, locale, cacheManager)
 {
     _apiKey = apiKey;
 }
コード例 #3
0
ファイル: ApiClient.cs プロジェクト: Xenophik/WContact
 /// <summary>
 ///   Constructor. Initializes a new instance of the ApiClient class
 /// </summary>
 /// <param name="region"> Regional battle.net Community website to which the ApiClient should connect to perform request. </param>
 /// <param name="apiKey"> Application key used to authenticate requests sent by the ApiClient </param>
 /// <param name="locale"> The locale to use to perform request (item names, class names, etc are retrieved in the locale specified) </param>
 /// <remarks>
 ///   Only Locales supported by the regional website that the ApiClient is connecting to are supported. If a wrong local is passed, default language is used.
 /// </remarks>
 protected ApiClient(string region, ApiKeyPair apiKey, string locale)
     : this(Region.GetRegion(region), apiKey, locale, null)
 {
 }
コード例 #4
0
ファイル: ApiClient.cs プロジェクト: Xenophik/WContact
 /// <summary>
 ///   Constructor. Initializes a new instance of the ApiClient class
 /// </summary>
 /// <param name="region"> Regional battle.net Community website to which the ApiClient should connect to perform request. </param>
 /// <param name="apiKey"> Application key used to authenticate requests sent by the ApiClient </param>
 /// <param name="locale"> The locale to use to perform request (item names, class names, etc are retrieved in the locale specified) </param>
 /// <param name="cacheManager"> Cache manager to cache data </param>
 /// <remarks>
 ///   Only Locales supported by the regional website that the ApiClient is connecting to are supported. If a wrong local is passed, default language is used.
 /// </remarks>
 protected ApiClient(string region, ApiKeyPair apiKey, string locale, ICacheManager cacheManager)
     : this(Region.GetRegion(region), apiKey, locale, cacheManager)
 {
 }
コード例 #5
0
ファイル: ApiClient.cs プロジェクト: Xenophik/WContact
 /// <summary>
 ///   Constructor. Initializes a new instance of the ApiClient class
 /// </summary>
 /// <param name="apiKey"> Application key used to authenticate requests sent by the ApiClient </param>
 protected ApiClient(ApiKeyPair apiKey)
     : this((Region)null, apiKey, null, null)
 {
 }