Ejemplo n.º 1
0
        /// <summary>
        /// Аутентификация по полученному токену
        /// </summary>
        /// <returns></returns>
        public OAuthLoginResponse Login()
        {
            OAuthLoginResponse loginResponse = new OAuthLoginResponse();
            string             providerName  = HttpContext.Current.Request.Params["providerName"];
            OAuthProviderBase  oAuthProvider = Providers.FirstOrDefault(provider => string.Equals(provider.ProviderName, providerName));

            if (oAuthProvider == null)
            {
                loginResponse.Success = false;
            }
            else
            {
                NameValueCollection response = oAuthProvider.SendTokenRequest();
                string token = response["access_token"];
                if (string.IsNullOrEmpty(token))
                {
                    loginResponse.Success = false;
                }
                else
                {
                    DateTime       tokenExpires   = GetTokenExpires(response);
                    CookieUserData cookieUserData = oAuthProvider.GetUserData(token, out loginResponse.Account);
                    User           user           = FindOrCreateUser(cookieUserData, out loginResponse.IsNewUser);
                    cookieUserData.UserId = user.Id;
                    CookieDataProvider.Login(user.Name, cookieUserData, tokenExpires);
                    loginResponse.Success = true;
                }
            }

            return(loginResponse);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Добавление OAuth-провайдера
 /// </summary>
 /// <param name="provider"></param>
 internal static void Add(OAuthProviderBase provider)
 {
     Providers.Add(provider);
 }