Ejemplo n.º 1
0
        /// <summary>
        /// 生成用户的公钥,返回加密UserId的加密串
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="userType"></param>
        /// <returns></returns>
        public string CreatePublicKey(int uid, AuthUserType userType)
        {
            var encryptStr = Execute(db =>
            {
                var authKey = db.AuthKeys.FirstOrDefault(u => u.UserId == uid && u.UserType == (int)userType);
                if (authKey != null)
                {
                    return(RSAHelper.EncryptString(uid.ToString(), authKey.PublicKey));
                }
                var keyPair = RSAHelper.GetRASKey();
                authKey     = new AuthKeys
                {
                    UserId     = uid,
                    PublicKey  = keyPair.PublicKey,
                    PrivateKey = keyPair.PrivateKey,
                    UserType   = (int)userType,
                    CreateTime = DateTime.Now
                };
                db.AuthKeys.Add(authKey);
                db.SaveChanges();
                return(RSAHelper.EncryptString(uid.ToString(), authKey.PublicKey));
            });

            CreateCache <AuthKeys>();
            return(encryptStr);
        }
Ejemplo n.º 2
0
 public MeetUp(AuthKeys aka, string RTM_Web_UI_Format)
 {
     keys       = aka;
     RTM_Web_UI = RTM_Web_UI_Format;
     mtc        = new MeetUp_Connect();
     jsmt       = new JsonMeetupAuth();
 }
Ejemplo n.º 3
0
        static public async Task RevokeToken(AuthKeys key, CancellationToken ct = default(CancellationToken))
        {
            if (key == null)
            {
                return;
            }

            Log("RevokeToken");
            using (var client = new HttpClient())
            {
                try
                {
                    var response = await client.GetAsync(
                        "https://accounts.google.com/o/oauth2/revoke?token=" + key.access_token,
                        ct
                        ).ConfigureAwait(false);

                    response.EnsureSuccessStatusCode();
                    string responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
                }
                catch (HttpRequestException ex)
                {
                    Log("RevokeToken", ex.Message);
                }
                catch (Exception ex)
                {
                    Log("RevokeToken", ex.ToString());
                }
            }
        }
Ejemplo n.º 4
0
        public void Link(PlayFabAuthService authService, AuthKeys authKeys)
        {
            Authenticate(authService, resultCallback =>
            {
#if UNITY_ANDROID && !UNITY_EDITOR
                PlayFabClientAPI.LinkAndroidDeviceID(new LinkAndroidDeviceIDRequest
                {
                    AndroidDeviceId       = PlayFabSettings.DeviceUniqueIdentifier,
                    AuthenticationContext = authService.AuthenticationContext,
                    AndroidDevice         = SystemInfo.deviceModel,
                    OS        = SystemInfo.operatingSystem,
                    ForceLink = authService.ForceLink
                }, linkCallback =>
                {
                    authService.InvokeLink(AuthTypes.Silent);
                }, errorCallback =>
                {
                    authService.InvokeLink(AuthTypes.Silent, errorCallback);
                });
#elif UNITY_IPHONE || UNITY_IOS && !UNITY_EDITOR
                PlayFabClientAPI.LinkIOSDeviceID(new LinkIOSDeviceIDRequest
                {
                    DeviceId = PlayFabSettings.DeviceUniqueIdentifier,
                    AuthenticationContext = authService.AuthenticationContext,
                    DeviceModel           = SystemInfo.deviceModel,
                    OS        = SystemInfo.operatingSystem,
                    ForceLink = authService.ForceLink
                }, linkCallback =>
                {
                    authService.InvokeLink(AuthTypes.Silent);
                }, errorCallback =>
                {
                    authService.InvokeLink(AuthTypes.Silent, errorCallback);
                });
#else
                PlayFabClientAPI.LinkCustomID(new LinkCustomIDRequest
                {
                    CustomId = authService.GetOrCreateRememberMeId(),
                    AuthenticationContext = authService.AuthenticationContext,
                    ForceLink             = authService.ForceLink
                }, linkCallback =>
                {
                    authService.InvokeLink(AuthTypes.Silent);
                }, errorCallback =>
                {
                    authService.InvokeLink(AuthTypes.Silent, errorCallback);
                });
#endif
            }, errorCallback =>
            {
                authService.InvokeLink(AuthTypes.Silent, errorCallback);
            }, authKeys);
        }
Ejemplo n.º 5
0
 public void Load(Func <string, byte[]> readbytes)
 {
     if (AuthKeys == null)
     {
         AuthKeys = new AuthKeyPair();
     }
     if (CryptKeys == null)
     {
         CryptKeys = new CryptKeyPair();
     }
     AuthKeys.Load(readbytes("BankAuthKeys.pubkey"));
     CryptKeys.Load(readbytes("BankCryptKeys.pubkey"));
 }
 public void Unlink(PlayFabAuthService authService, AuthKeys authKeys)
 {
     PlayFabClientAPI.UnlinkGoogleAccount(new UnlinkGoogleAccountRequest
     {
         AuthenticationContext = authService.AuthenticationContext,
     }, resultCallback =>
     {
         authService.InvokeUnlink(AuthTypes.GooglePlayGames);
     }, errorCallback =>
     {
         authService.InvokeUnlink(AuthTypes.GooglePlayGames, errorCallback);
     });
 }
Ejemplo n.º 7
0
        static public AuthKeys ParseAuthResponse(string response)
        {
            AuthKeys key        = new AuthKeys();
            var      serializer = new DataContractJsonSerializer(typeof(Authentication_Info));

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(response)))
            {
                var data = (Authentication_Info)serializer.ReadObject(ms);
                key.access_token  = data.access_token;
                key.refresh_token = data.refresh_token;
            }
            return(key);
        }
Ejemplo n.º 8
0
 public void Unlink(PlayFabAuthService authService, AuthKeys authKeys)
 {
     PlayFabClientAPI.UnlinkTwitch(new UnlinkTwitchAccountRequest
     {
         AuthenticationContext = authService.AuthenticationContext,
     }, resultCallback =>
     {
         authService.InvokeUnlink(AuthTypes.Twitch);
     }, errorCallback =>
     {
         authService.InvokeUnlink(AuthTypes.Twitch, errorCallback);
     });
 }
Ejemplo n.º 9
0
 public void Unlink(PlayFabAuthService authService, AuthKeys authKeys)
 {
     PlayFabClientAPI.UnlinkOpenIdConnect(new UninkOpenIdConnectRequest
     {
         AuthenticationContext = authService.AuthenticationContext,
         ConnectionId          = authKeys.OpenIdConnectionId
     }, resultCallback =>
     {
         authService.InvokeUnlink(AuthTypes.OpenId);
     }, errorCallback =>
     {
         authService.InvokeUnlink(AuthTypes.OpenId, errorCallback);
     });
 }
 public void Unlink(PlayFabAuthService authService, AuthKeys authKeys)
 {
     PlayFabClientAPI.UnlinkWindowsHello(new UnlinkWindowsHelloAccountRequest
     {
         AuthenticationContext = authService.AuthenticationContext,
         PublicKeyHint         = authKeys.AuthTicket
     }, resultCallback =>
     {
         authService.InvokeUnlink(AuthTypes.WindowsHello);
     }, errorCallback =>
     {
         authService.InvokeUnlink(AuthTypes.WindowsHello, errorCallback);
     });
 }
Ejemplo n.º 11
0
 public void Unlink(PlayFabAuthService authService, AuthKeys authKeys)
 {
     PlayFabClientAPI.UnlinkXboxAccount(new UnlinkXboxAccountRequest
     {
         AuthenticationContext = authService.AuthenticationContext,
         XboxToken             = authKeys.AuthTicket
     }, resultCallback =>
     {
         authService.InvokeUnlink(AuthTypes.XBoxLive);
     }, errorCallback =>
     {
         authService.InvokeUnlink(AuthTypes.XBoxLive, errorCallback);
     });
 }
Ejemplo n.º 12
0
 public void Unlink(PlayFabAuthService authService, AuthKeys authKeys)
 {
     PlayFabClientAPI.UnlinkFacebookInstantGamesId(new UnlinkFacebookInstantGamesIdRequest
     {
         AuthenticationContext  = authService.AuthenticationContext,
         FacebookInstantGamesId = authKeys.AuthTicket
     }, resultCallback =>
     {
         authService.InvokeUnlink(AuthTypes.FacebookInstantGames);
     }, errorCallback =>
     {
         authService.InvokeUnlink(AuthTypes.FacebookInstantGames, errorCallback);
     });
 }
 public void Unlink(PlayFabAuthService authService, AuthKeys authKeys)
 {
     PlayFabClientAPI.UnlinkNintendoSwitchDeviceId(new UnlinkNintendoSwitchDeviceIdRequest
     {
         AuthenticationContext  = authService.AuthenticationContext,
         NintendoSwitchDeviceId = PlayFabSettings.DeviceUniqueIdentifier
     }, resultCallback =>
     {
         authService.InvokeUnlink(AuthTypes.NintendoSwitch);
     }, errorCallback =>
     {
         authService.InvokeUnlink(AuthTypes.NintendoSwitch, errorCallback);
     });
 }
Ejemplo n.º 14
0
 public void Link(PlayFabAuthService authService, AuthKeys authKeys)
 {
     PlayFabClientAPI.LinkFacebookInstantGamesId(new LinkFacebookInstantGamesIdRequest
     {
         FacebookInstantGamesSignature = authKeys.AuthTicket,
         AuthenticationContext         = authService.AuthenticationContext,
         ForceLink = authService.ForceLink
     }, resultCallback =>
     {
         authService.InvokeLink(AuthTypes.FacebookInstantGames);
     }, errorCallback =>
     {
         authService.InvokeLink(AuthTypes.FacebookInstantGames, errorCallback);
     });
 }
Ejemplo n.º 15
0
 public void Link(PlayFabAuthService authService, AuthKeys authKeys)
 {
     PlayFabClientAPI.LinkTwitch(new LinkTwitchAccountRequest
     {
         AccessToken           = authKeys.AuthTicket,
         AuthenticationContext = authService.AuthenticationContext,
         ForceLink             = authService.ForceLink
     }, resultCallback =>
     {
         authService.InvokeLink(AuthTypes.Twitch);
     }, errorCallback =>
     {
         authService.InvokeLink(AuthTypes.Twitch, errorCallback);
     });
 }
Ejemplo n.º 16
0
 public void Link(PlayFabAuthService authService, AuthKeys authKeys)
 {
     PlayFabClientAPI.LinkGameCenterAccount(new LinkGameCenterAccountRequest
     {
         GameCenterId          = authKeys.AuthTicket,
         AuthenticationContext = authService.AuthenticationContext,
         ForceLink             = authService.ForceLink
     }, resultCallback =>
     {
         authService.InvokeLink(AuthTypes.GameCenter);
     }, errorCallback =>
     {
         authService.InvokeLink(AuthTypes.GameCenter, errorCallback);
     });
 }
 public void Link(PlayFabAuthService authService, AuthKeys authKeys)
 {
     PlayFabClientAPI.LinkGoogleAccount(new LinkGoogleAccountRequest
     {
         ServerAuthCode        = authKeys.AuthTicket,
         AuthenticationContext = authService.AuthenticationContext,
         ForceLink             = authService.ForceLink
     }, resultCallback =>
     {
         authService.InvokeLink(AuthTypes.GooglePlayGames);
     }, errorCallback =>
     {
         authService.InvokeLink(AuthTypes.GooglePlayGames, errorCallback);
     });
 }
 public void Link(PlayFabAuthService authService, AuthKeys authKeys)
 {
     PlayFabClientAPI.LinkKongregate(new LinkKongregateAccountRequest
     {
         KongregateId          = authKeys.AuthTicket,
         AuthenticationContext = authService.AuthenticationContext,
         ForceLink             = authService.ForceLink
     }, resultCallback =>
     {
         authService.InvokeLink(AuthTypes.Kongregate);
     }, errorCallback =>
     {
         authService.InvokeLink(AuthTypes.Kongregate, errorCallback);
     });
 }
Ejemplo n.º 19
0
 public void Link(PlayFabAuthService authService, AuthKeys authKeys)
 {
     PlayFabClientAPI.LinkOpenIdConnect(new LinkOpenIdConnectRequest
     {
         IdToken               = authKeys.AuthTicket,
         ConnectionId          = authKeys.OpenIdConnectionId,
         AuthenticationContext = authService.AuthenticationContext,
         ForceLink             = authService.ForceLink
     }, resultCallback =>
     {
         authService.InvokeLink(AuthTypes.OpenId);
     }, errorCallback =>
     {
         authService.InvokeLink(AuthTypes.OpenId, errorCallback);
     });
 }
 public void Link(PlayFabAuthService authService, AuthKeys authKeys)
 {
     PlayFabClientAPI.LinkWindowsHello(new LinkWindowsHelloAccountRequest
     {
         PublicKey             = authKeys.AuthTicket,
         AuthenticationContext = authService.AuthenticationContext,
         ForceLink             = authService.ForceLink,
         UserName = authService.Username
     }, resultCallback =>
     {
         authService.InvokeLink(AuthTypes.WindowsHello);
     }, errorCallback =>
     {
         authService.InvokeLink(AuthTypes.WindowsHello, errorCallback);
     });
 }
Ejemplo n.º 21
0
        /// <summary
        /// This is main method for converting meetup data into RTM tasks
        /// </summary>
        /// <see href="https://www.newtonsoft.com/json">newtonsoft.com/json</see>
        /// <see href="https://www.meetup.com/meetup_api/docs/self/events/">Meetup Events API Documentation</see>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void Click_Button(object sender, RoutedEventArgs e)
        {
            string rtmCon    = "RTM: Innitiate Connection...now...";
            string meetupCon = "MeetUp: Innitiate Connection...now...";

            ak = new AuthKeys
            {
                MyRTMkey          = iniConfigOfSecrets[2] ?? RTMkey.Text,
                MyRTMsecret       = iniConfigOfSecrets[3] ?? RTMsecret.Text,
                MyMeetupKey       = iniConfigOfSecrets[0] ?? MeetupKey.Text,
                MyMeetupKeySecret = iniConfigOfSecrets[1] ?? MeetupSecretKey.Text
            };

            meetup = new MeetUp(ak, RTM_Web_UI_Format.Text);
            rtm    = new RTM();

            // initiate RTM connection
            SetLoggingMessage_Other(rtmCon);
            rtm.InitiateConnection(ak);
            logger.Info("Done with RTM authKeys");

            // initiate Meetup connection
            SetLoggingMessage_Other(meetupCon);
            meetup.InitiateConnection();
            logger.Info("Done with MeetUp 'code' key");

            // open meetup dialog where you can insert code
            // https://stackoverflow.com/questions/2796470/wpf-create-a-dialog-prompt
            var myDia = new Dialog(ak);

            myDia.ShowDialog();
            Console.WriteLine("Meetup: so far correct! token: " + ak.MyMeetupCode);
            var JsOb = meetup.AuthorizeTokenAsync(ak.MyMeetupCode);

            logger.Info("Done with Meetup authKeys: " + JsOb.access_token);
            SetLoggingMessage_Other("Done with Meetup authKeys" + JsOb.access_token);

            string meetupDataURL   = meetup.CreateDataURL();
            var    meetupEventData = meetup.GetMeetupData(meetupDataURL);

            meetup.GetSampleData(meetupEventData);
            var rtmMeetupTasksData = meetup.Create_RTM_Tasks_From_Events(meetupEventData);
            var mu_event_venue     = meetup.PrepareMeetupTaskList_Venue_ToString(meetupEventData);

            rtm.SetRTMTasks(meetupEventData, rtmMeetupTasksData, mu_event_venue, checkbox_value);
        }
Ejemplo n.º 22
0
        static public async Task <string> RefreshAuthorizationCode(AuthKeys key, CancellationToken ct = default(CancellationToken))
        {
            Log("RefreshAuthorizationCode");
            if (key.refresh_token == null)
            {
                throw new ArgumentNullException("refresh_token");
            }
            using (var client = new HttpClient())
            {
                try
                {
                    //Log("RefreshAuthorizationCode");
                    var response = await client.PostAsync(
                        (string.IsNullOrEmpty(ConfigAPI.client_secret))?ConfigAPI.App_RefreshToken : ConfigAPI.token_uri,
                        new FormUrlEncodedContent(new Dictionary <string, string> {
                        { "grant_type", "refresh_token" },
                        { "refresh_token", key.refresh_token },
                        { "client_id", string.IsNullOrEmpty(ConfigAPI.client_secret) ? ConfigAPI.client_id_web: ConfigAPI.client_id },
                        { "client_secret", ConfigAPI.client_secret },
                    }),
                        ct
                        ).ConfigureAwait(false);

                    response.EnsureSuccessStatusCode();
                    string responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    var newkey = ParseAuthResponse(responseBody);
                    return(newkey.access_token);
                }
                catch (HttpRequestException ex)
                {
                    Log("RefreshAuthorizationCode", ex.Message);
                }
                catch (OperationCanceledException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    Log("RefreshAuthorizationCode", ex.ToString());
                }
            }
            return(null);
        }
Ejemplo n.º 23
0
        public void Unlink(PlayFabAuthService authService, AuthKeys authKeys)
        {
            Authenticate(authService, resultCallback =>
            {
#if UNITY_ANDROID && !UNITY_EDITOR
                PlayFabClientAPI.UnlinkAndroidDeviceID(new UnlinkAndroidDeviceIDRequest()
                {
                    AndroidDeviceId       = PlayFabSettings.DeviceUniqueIdentifier,
                    AuthenticationContext = authService.AuthenticationContext
                }, unlinkCallback =>
                {
                    authService.InvokeUnlink(AuthTypes.Silent);
                }, errorCallback =>
                {
                    authService.InvokeUnlink(AuthTypes.Silent, errorCallback);
                });
#elif UNITY_IPHONE || UNITY_IOS && !UNITY_EDITOR
                PlayFabClientAPI.UnlinkIOSDeviceID(new UnlinkIOSDeviceIDRequest()
                {
                    DeviceId = PlayFabSettings.DeviceUniqueIdentifier,
                    AuthenticationContext = authService.AuthenticationContext
                }, unlinkCallback =>
                {
                    authService.InvokeUnlink(AuthTypes.Silent);
                }, errorCallback =>
                {
                    authService.InvokeUnlink(AuthTypes.Silent, errorCallback);
                });
#else
                PlayFabClientAPI.UnlinkCustomID(new UnlinkCustomIDRequest
                {
                    CustomId = authService.GetOrCreateRememberMeId(),
                    AuthenticationContext = authService.AuthenticationContext
                }, unlinkCallback =>
                {
                    authService.InvokeUnlink(AuthTypes.Silent);
                }, errorCallback =>
                {
                    authService.InvokeUnlink(AuthTypes.Silent, errorCallback);
                });
#endif
            }, errorCallback => authService.InvokeUnlink(AuthTypes.Silent, errorCallback), authKeys);
        }
Ejemplo n.º 24
0
        private void CheckKey(int uid, AuthUserType userType, out AuthKeys authKeys)
        {
            var condtions = new List <Condtion>
            {
                new Condtion
                {
                    FiledName       = "UserId",
                    FiledValue      = uid,
                    ExpressionLogic = ExpressionLogic.And,
                    ExpressionType  = ExpressionType.Equal
                },
                new Condtion
                {
                    FiledName       = "UserType",
                    FiledValue      = (int)userType,
                    ExpressionLogic = ExpressionLogic.And,
                    ExpressionType  = ExpressionType.Equal
                }
            };

            authKeys = _authKeysRepository.GetEntity(condtions);
        }
Ejemplo n.º 25
0
        internal static void Load()
        {
            if (!File.Exists(keyfile))
            {
                return;
            }

            try
            {
                DataContractSerializer reader =
                    new DataContractSerializer(typeof(AuthKeys),
                                               new Type[] { typeof(AuthKey) });

                using (var fs = new FileStream(keyfile, FileMode.Open))
                    using (var sr = new CryptoStream(fs, Rij.algorithm.CreateDecryptor(), CryptoStreamMode.Read))
                    {
                        Keys = (AuthKeys)reader.ReadObject(sr);
                    }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }
Ejemplo n.º 26
0
        private void but_signkey_Click(object sender, EventArgs e)
        {
            var auth = new AuthKeys();

            auth.Show();
        }
Ejemplo n.º 27
0
 public bool CreateEntity(AuthKeys entity)
 {
     return(base.CreateEntity(entity));
 }
Ejemplo n.º 28
0
        public void Authenticate(PlayFabAuthService authService, Action <LoginResult> resultCallback, Action <PlayFabError> errorCallback, AuthKeys authKeys)
        {
            if (authKeys == null || string.IsNullOrEmpty(authKeys.AuthTicket))
            {
                authService.InvokeDisplayAuthentication();
                return;
            }

            PlayFabClientAPI.LoginWithFacebookInstantGamesId(new LoginWithFacebookInstantGamesIdRequest
            {
                FacebookInstantGamesSignature = authKeys.AuthTicket,
                InfoRequestParameters         = authService.InfoRequestParams,
                CreateAccount = true
            }, resultCallback, errorCallback);
        }
Ejemplo n.º 29
0
 public bool UpdateEntity(AuthKeys entity)
 {
     return(base.UpdateEntity(entity));
 }
Ejemplo n.º 30
0
 public bool DeleteEntity(AuthKeys entity)
 {
     return(base.DeleteEntity(entity));
 }