コード例 #1
0
        /// <summary>
        /// Processes authentication result from the server.
        /// Method could return synchronously or asynchronously.
        /// </summary>
        private void ProcessAuthResponse(string responseData, Action<LiveLoginResult> callback)
        {
            if (string.IsNullOrEmpty(responseData))
            {
                // non-connected user scenario. return status unknown.
                callback(new LiveLoginResult(LiveConnectSessionStatus.Unknown, null));
                return;
            }

            Uri responseUrl;
            try
            {
                responseUrl = new Uri(responseData, UriKind.Absolute);
            }
            catch (FormatException)
            {
                callback(new LiveLoginResult(
                    new LiveAuthException(AuthErrorCodes.ServerError, ResourceHelper.GetString("ServerError"))));
                return;
            }

            if (!string.IsNullOrEmpty(responseUrl.Fragment))
            {
                callback(this.ParseResponseFragment(responseUrl.Fragment));
                return;
            }

            if (!string.IsNullOrEmpty(responseUrl.Query))
            {
                IDictionary<string, object> parameters = LiveAuthClient.ParseQueryString(responseUrl.Query);
                if (parameters.ContainsKey(AuthConstants.Code))
                {
                    var authCode = parameters[AuthConstants.Code] as string;
                    if (!string.IsNullOrEmpty(authCode))
                    {
                        var refreshOp = new RefreshTokenOperation(
                            this, 
                            this.clientId,
                            authCode,
                            this.redirectUri,
                            this.syncContext);

                        refreshOp.OperationCompletedCallback = callback;
                        refreshOp.Execute();

                        return;
                    }
                }
                else if (parameters.ContainsKey(AuthConstants.Error))
                {
                    callback(GetErrorResult(parameters));
                    return;
                }
            }

            callback(
                new LiveLoginResult(
                    new LiveAuthException(AuthErrorCodes.ServerError, ResourceHelper.GetString("ServerError"))));
        }
コード例 #2
0
        /// <summary>
        /// Retrieve a new access token based on current session information.
        /// </summary>
        internal bool RefreshToken(Action<LiveLoginResult> completionCallback)
        {
            if (this.Session == null || this.Session.IsValid)
            {
                return false;
            }

            var refreshOp = new RefreshTokenOperation(
                this,
                this.clientId,
                this.Session.RefreshToken,
                this.Session.Scopes,
                null)
            {
                OperationCompletedCallback = completionCallback
            };

            refreshOp.Execute();

            return true;
        }