Exemple #1
0
        /// <summary>
        /// Reads authorization code from current session.
        /// </summary>
        public static bool ReadAuthCodeRequest(
            HttpContextBase webContext,
            out string code,
            out string state,
            out string requestTs,
            out LiveAuthException error)
        {
            Debug.Assert(webContext != null);

            NameValueCollection queryString = webContext.Request.QueryString;

            code = queryString[AuthConstants.Code];
            bool isCodeRequest = !string.IsNullOrEmpty(code);

            string clientState = queryString[AuthConstants.ClientState];
            IDictionary <string, string> states = LiveAuthUtility.DecodeAppRequestStates(clientState);

            state     = states.ContainsKey(AuthConstants.AppState) ? states[AuthConstants.AppState] : null;
            requestTs = states.ContainsKey(AuthConstants.ClientRequestTs) ? states[AuthConstants.ClientRequestTs] : null;

            string errorCode        = queryString[AuthConstants.Error];
            string errorDescription = queryString[AuthConstants.ErrorDescription];

            error = string.IsNullOrEmpty(errorCode) ? null : new LiveAuthException(errorCode, errorDescription, state);

            return(isCodeRequest);
        }