Exemplo n.º 1
0
        /// <summary>
        /// Получить токен из адреса
        /// </summary>
        /// <param name="uri">Адрес, полученный после OAuth авторизации</param>
        /// <returns></returns>
        public static OAuthResult Parse(Uri uri)
        {
            var p = ParseInternal(uri);
            if (p == null)
                return null;

            var result = new OAuthResult();
            result.AccessToken = new AccessToken();

            if (p.ContainsKey("error"))
                result.Error = p["error"];

            if (p.ContainsKey("error_description"))
                result.ErrorDescription = p["error_description"];

            if (p.ContainsKey("code"))
                result.Code = p["code"];

            if (p.ContainsKey("token"))
                result.Code = p["token"];

            if (p.ContainsKey("access_token"))
                result.AccessToken.Token = p["access_token"];

            if (p.ContainsKey("expires_in"))
                result.AccessToken.ExpiresIn = DateTime.Now.Add(TimeSpan.FromSeconds(double.Parse(p["expires_in"])));

            if (p.ContainsKey("user_id"))
                result.AccessToken.UserId = long.Parse(p["user_id"]);

            return result;
        }
        /// <summary>
        /// Получить токен из адреса
        /// </summary>
        /// <param name="uri">Адрес, полученный после OAuth авторизации</param>
        /// <returns></returns>
        public static OAuthResult Parse(Uri uri)
        {
            var p = ParseInternal(uri);

            if (p == null)
            {
                return(null);
            }

            var result = new OAuthResult();

            result.AccessToken = new AccessToken();

            if (p.ContainsKey("error"))
            {
                result.Error = p["error"];
            }

            if (p.ContainsKey("error_description"))
            {
                result.ErrorDescription = p["error_description"];
            }

            if (p.ContainsKey("code"))
            {
                result.Code = p["code"];
            }

            if (p.ContainsKey("token"))
            {
                result.Code = p["token"];
            }

            if (p.ContainsKey("access_token"))
            {
                result.AccessToken.Token = p["access_token"];
            }

            if (p.ContainsKey("expires_in"))
            {
                result.AccessToken.ExpiresIn = DateTime.Now.Add(TimeSpan.FromSeconds(double.Parse(p["expires_in"])));
            }

            if (p.ContainsKey("user_id"))
            {
                result.AccessToken.UserId = long.Parse(p["user_id"]);
            }

            return(result);
        }
 public OAuthResult ProcessAuth(Uri uri)
 {
     return(OAuthResult.Parse(uri));
 }