Example #1
0
        private static void T_Authenticate(object source, AuthArgs e)
        {
            Form form = source as Form;

            try
            {
                DataTable DT = Utils.DB.ExecuteReader(string.Format("SELECT id, shift_id, full_name, (permission->>'read')::boolean, (permission->>'write')::boolean, (permission->>'delete')::boolean FROM {0}_users WHERE username = '******' AND password = MD5(MD5(MD5('{2}'))) AND status", Utils.PREFIX, e.Username, e.Password));
                if (DT.Rows.Count > 0)
                {
                    User.ID       = (int)DT.Rows[0][0];
                    User.ShiftID  = (int)DT.Rows[0][1];
                    User.FullName = (string)DT.Rows[0][2];
                    User.Can      = new User.Permission((bool)DT.Rows[0][3], (bool)DT.Rows[0][4], (bool)DT.Rows[0][5]);
                    Console.WriteLine("{0}; {1}; {2}; {3};", User.ID, User.ShiftID, User.FullName, User.Can);
                    form.DialogResult = DialogResult.OK;
                }
                else
                {
                    FS.Notify.Error(form, "Логин и/или пароль неверно!");
                }
            } catch (Exception ex)
            {
                Console.WriteLine("Exception: {0}", ex.Message);
                FS.Notify.Error(form, "Database error!!!");
            }
        }
        public void AuthGetAccessToken(AuthArgs args)
        {
            var requestToken       = args.InternalData["requestToken"] as string;
            var requestTokenSecret = args.InternalData["requestTokenSecret"] as string;

            var hyvesSession = this.LoadHyvesSession(args);

            var      hyvesRequest = new HyvesRequest(hyvesSession);
            string   userId;
            string   accessTokenSecret;
            DateTime expireDate;
            var      accessToken = hyvesRequest.CreateAccessToken(requestToken, requestTokenSecret, out accessTokenSecret, out userId, out expireDate);

            var authCompletedArgs = new AuthCompletedArgs
            {
                Application                 = args.Application,
                AccessToken                 = accessToken,
                AccessTokenSecret           = accessTokenSecret,
                CallbackPage                = args.CallbackPage,
                ExternalData                = args.ExternalData,
                AttachAccountToLoggedInUser = args.AttachAccountToLoggedInUser,
                IsAsyncProfileUpdate        = args.IsAsyncProfileUpdate
            };

            if (!string.IsNullOrEmpty(args.CallbackType))
            {
                this.InvokeAuthCompleted(args.CallbackType, authCompletedArgs);
            }
        }
    public void AuthGetAccessToken(AuthArgs args)
    {
      var requestToken = args.InternalData["requestToken"] as string;
      var requestTokenSecret = args.InternalData["requestTokenSecret"] as string;

      var hyvesSession = this.LoadHyvesSession(args);

      var hyvesRequest = new HyvesRequest(hyvesSession);
      string userId;
      string accessTokenSecret;
      DateTime expireDate;
      var accessToken = hyvesRequest.CreateAccessToken(requestToken, requestTokenSecret, out accessTokenSecret, out userId, out expireDate);

      var authCompletedArgs = new AuthCompletedArgs
      {
        Application = args.Application,
        AccessToken = accessToken,
        AccessTokenSecret = accessTokenSecret,
        CallbackPage = args.CallbackPage,
        ExternalData = args.ExternalData,
        AttachAccountToLoggedInUser = args.AttachAccountToLoggedInUser,
        IsAsyncProfileUpdate = args.IsAsyncProfileUpdate
      };
      if (!string.IsNullOrEmpty(args.CallbackType))
      {
        this.InvokeAuthCompleted(args.CallbackType, authCompletedArgs);
      }
    }
 private HyvesServerSession LoadHyvesSession(AuthArgs authArgs)
 {
   var hyvesSessionState = (HyvesSessionState)authArgs.InternalData["hyvesSessionState"];
   var hyvesServerSession = new HyvesServerSession(authArgs.Application.ApplicationKey, authArgs.Application.ApplicationSecret, new List<HyvesMethod>());
   hyvesServerSession.LoadState(hyvesSessionState);
   return hyvesServerSession;
 }
        private void SaveHyvesSession(AuthArgs authArgs, HyvesServerSession hyvesServerSession)
        {
            var hyvesSessionState = hyvesServerSession.SaveState();

            authArgs.InternalData["hyvesSessionState"] = hyvesSessionState;
            new AuthManager().UpdateAuthArgs(authArgs);
        }
        private HyvesServerSession LoadHyvesSession(AuthArgs authArgs)
        {
            var hyvesSessionState  = (HyvesSessionState)authArgs.InternalData["hyvesSessionState"];
            var hyvesServerSession = new HyvesServerSession(authArgs.Application.ApplicationKey, authArgs.Application.ApplicationSecret, new List <HyvesMethod>());

            hyvesServerSession.LoadState(hyvesSessionState);
            return(hyvesServerSession);
        }
Example #7
0
        static void Main(string[] args)
        {
            var auth = new rsid.Authenticator();

            if (auth.Connect(new SerialConfig {
                port = "COM9"
            }) != Status.Ok)
            {
                System.Console.WriteLine("Error connecting to device:");
            }
            var authArgs = new AuthArgs {
                hintClbk = OnAuthHint, resultClbk = OnAuthResult, faceDetectedClbk = OnFaceDeteced
            };

            auth.Authenticate(authArgs);
        }
    public void AuthGetCode(AuthArgs args)
    {
      var hyvesMethods = new List<HyvesMethod>
      {
        HyvesMethod.All
      };
      var hyvesSession = new HyvesServerSession(args.Application.ApplicationKey, args.Application.ApplicationSecret, hyvesMethods);

      var hyvesRequest = new HyvesRequest(hyvesSession);
      string tokenSecret;
      var requestToken = hyvesRequest.CreateRequestToken(out tokenSecret, HyvesExpirationType.Infinite);

      args.InternalData["requestToken"] = requestToken;
      args.InternalData["requestTokenSecret"] = tokenSecret;

      this.SaveHyvesSession(args, hyvesSession);

      var request = HttpContext.Current.Request;
      var oauthCallback = string.Format("{0}://{1}{2}?type=access&state={3}", request.Url.Scheme, request.Url.Host, Paths.SocialLoginHandlerPath, args.StateKey);

      var hyvesAuthUrl = string.Format("http://www.hyves.nl/api/authorize/?oauth_token={0}&oauth_callback={1}", requestToken, HttpUtility.UrlEncode(oauthCallback));
      HttpContext.Current.Response.Redirect(hyvesAuthUrl);
    }
Example #9
0
        public void AuthGetCode(AuthArgs args)
        {
            this._provider.ClientIdentifier = (args.Application.ApplicationKey);
            this._provider.ClientSecret     = (args.Application.ApplicationSecret);
            List <string>      list1  = GetScopes();
            AuthorizationState state1 = new AuthorizationState(list1);

            state1.Callback = (new Uri(WebUtil.GetFullUrl("/layouts/Social/Connector/SocialLogin.ashx?type=access")));
            AuthorizationState state = state1;
            string             str   = this._provider.RequestUserAuthorization(state).ToString();

            if (args.Permissions != null)
            {
                bool flag;
                bool flag1 = bool.TryParse(args.Permissions["offlineAccess"], out flag);
                if ((args.Permissions.ContainsKey("offlineAccess") && flag1) & flag)
                {
                    str = str + "&access_type=offline&approval_prompt=force";
                }
            }

            RedirectUtil.Redirect(str + "&state=" + args.StateKey);
        }
        public void AuthGetCode(AuthArgs args)
        {
            var hyvesMethods = new List <HyvesMethod>
            {
                HyvesMethod.All
            };
            var hyvesSession = new HyvesServerSession(args.Application.ApplicationKey, args.Application.ApplicationSecret, hyvesMethods);

            var    hyvesRequest = new HyvesRequest(hyvesSession);
            string tokenSecret;
            var    requestToken = hyvesRequest.CreateRequestToken(out tokenSecret, HyvesExpirationType.Infinite);

            args.InternalData["requestToken"]       = requestToken;
            args.InternalData["requestTokenSecret"] = tokenSecret;

            this.SaveHyvesSession(args, hyvesSession);

            var request       = HttpContext.Current.Request;
            var oauthCallback = string.Format("{0}://{1}{2}?type=access&state={3}", request.Url.Scheme, request.Url.Host, Paths.SocialLoginHandlerPath, args.StateKey);

            var hyvesAuthUrl = string.Format("http://www.hyves.nl/api/authorize/?oauth_token={0}&oauth_callback={1}", requestToken, HttpUtility.UrlEncode(oauthCallback));

            HttpContext.Current.Response.Redirect(hyvesAuthUrl);
        }
 private void SaveHyvesSession(AuthArgs authArgs, HyvesServerSession hyvesServerSession)
 {
   var hyvesSessionState = hyvesServerSession.SaveState();
   authArgs.InternalData["hyvesSessionState"] = hyvesSessionState;
   new AuthManager().UpdateAuthArgs(authArgs);
 }
Example #12
0
        public void AuthGetAccessToken(AuthArgs args)
        {
            HttpRequest request = HttpContext.Current.Request;

            if (!string.IsNullOrEmpty(request.QueryString.Get("error")))
            {
                return;
            }
            else
            {
                string str = request.QueryString.Get("code");
                if (string.IsNullOrEmpty(str))
                {
                    return;
                }
                else
                {
                    this._provider.ClientIdentifier = (args.Application.ApplicationKey);
                    this._provider.ClientSecret     = (args.Application.ApplicationSecret);
                    List <string>      list1  = GetScopes();
                    AuthorizationState state1 = new AuthorizationState(list1);
                    state1.Callback =
                        (new Uri(WebUtil.GetFullUrl("/layouts/Social/Connector/SocialLogin.ashx?type=access")));
                    AuthorizationState state = state1;
                    try
                    {
                        this._auth = this._provider.ProcessUserAuthorization(str, state);
                    }
                    catch (WebException exception)
                    {
                        using (WebResponse response = exception.Response)
                        {
                            using (Stream stream = response.GetResponseStream())
                            {
                                if (stream != null)
                                {
                                    string message = new StreamReader(stream).ReadToEnd();
                                    ExecutingContext.Current.IoC.Get <ILogManager>(new IParameter[0]).LogMessage(message,
                                                                                                                 Sitecore.Social.Infrastructure.Logging.LogLevel.Error, this, exception);
                                }
                            }
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(args.CallbackType))
            {
                AuthCompletedArgs args1 = new AuthCompletedArgs();
                args1.Application       = args.Application;
                args1.AccessTokenSecret = this._auth.AccessToken;
                args1.RefreshToken      = this._auth.RefreshToken;
                args1.AccessTokenSecretExpirationDate = this._auth.AccessTokenExpirationUtc;
                args1.AccessTokenSecretIssueDate      = this._auth.AccessTokenIssueDateUtc;
                args1.CallbackPage = args.CallbackUrl;
                args1.ExternalData = args.ExternalData;
                args1.AttachAccountToLoggedInUser = args.AttachAccountToLoggedInUser;
                args1.IsAsyncProfileUpdate        = args.IsAsyncProfileUpdate;
                AuthCompletedArgs authCompletedArgs = args1;
                base.InvokeAuthCompleted(args.CallbackType, authCompletedArgs);
            }
        }
Example #13
0
 public AuthInfo Login(AuthArgs authInfo)
 {
     //todo нужно сделать нормальное решение
     authService.ActionContext = ActionContext;
     return(authService.Login(authInfo));
 }