public Task <XboxLiveHttpResponse> GetResponseWithAuth(XboxLiveUser user, HttpCallResponseBodyType httpCallResponseBodyType)
        {
            TaskCompletionSource <XboxLiveHttpResponse> getResponseCompletionSource = new TaskCompletionSource <XboxLiveHttpResponse>();

            user.GetTokenAndSignatureAsync(this.Method, this.Url, this.Headers).ContinueWith(
                tokenTask =>
            {
                if (tokenTask.IsFaulted)
                {
                    getResponseCompletionSource.SetException(tokenTask.Exception);
                    return;
                }

                var result = tokenTask.Result;
#if !WINDOWS_UWP
                this.SetCustomHeader(AuthorizationHeaderName, string.Format("XBL3.0 x={0};{1}", result.XboxUserHash, result.Token));
#else
                this.SetCustomHeader(AuthorizationHeaderName, string.Format("{0}", result.Token));
#endif
                this.SetCustomHeader(SignatureHeaderName, tokenTask.Result.Signature);
                try
                {
                    this.GetResponseWithoutAuth(httpCallResponseBodyType).ContinueWith(getResponseTask =>
                    {
                        if (getResponseTask.IsFaulted)
                        {
                            getResponseCompletionSource.SetException(getResponseTask.Exception);
                        }

                        getResponseCompletionSource.SetResult(getResponseTask.Result);
                    });
                }
                catch (Exception e)
                {
                    getResponseCompletionSource.SetException(e);
                }
            });

            return(getResponseCompletionSource.Task);
        }
示例#2
0
        public Task <XboxLiveHttpResponse> GetResponseWithAuth(XboxLiveUser user)
        {
            TaskCompletionSource <XboxLiveHttpResponse> taskCompletionSource = new TaskCompletionSource <XboxLiveHttpResponse>();

            this.User = user;

            user.GetTokenAndSignatureAsync(this.Method, this.Url, this.Headers).ContinueWith(
                tokenTask =>
            {
                if (tokenTask.IsFaulted)
                {
                    taskCompletionSource.SetException(tokenTask.Exception);
                    return;
                }

                try
                {
                    this.SetAuthHeaders(tokenTask.Result);
                    this.SetRequestHeaders();
                    this.InternalGetResponse().ContinueWith(getResponseTask =>
                    {
                        if (getResponseTask.IsFaulted)
                        {
                            taskCompletionSource.SetException(getResponseTask.Exception);
                        }
                        else
                        {
                            taskCompletionSource.SetResult(getResponseTask.Result);
                        }
                    });
                }
                catch (Exception e)
                {
                    taskCompletionSource.SetException(e);
                }
            });

            return(taskCompletionSource.Task);
        }