Example #1
0
        /// <summary>
        /// 验证凭据。
        /// </summary>
        /// <param name="userField">该参数将被忽略。</param>
        /// <returns>身份验证结果。</returns>
        public AuthResult Auth(bool userField = false)
        {
            var authProperty = new AuthPropertyModel
            {
                Name      = "preferredLanguage",
                ProfileId = string.Empty,
                UserId    = PlayerUUID.Random(),
                Value     = "zh-cn"
            };

            var uuid   = PlayerUUID.FromOfflinePlayerName(Username);
            var result = new AuthResult
            {
                AccessToken     = GuidHelper.NewGuidString(),
                AuthStatus      = AuthStatus.Succeeded,
                SelectedProfile = new ProfileInfoModel
                {
                    Name = Username,
                    UUID = uuid
                },
                User = new UserInfoModel
                {
                    UUID       = uuid,
                    Properties = new List <PropertyModel>
                    {
                        new PropertyModel
                        {
                            Name  = authProperty.Name,
                            Value = authProperty.Value
                        }
                    }
                }
            };

            var authInfo = new AuthInfoModel
            {
                UserName = Username,
                Profiles = new Dictionary <PlayerUUID, AuthProfileModel>
                {
                    { result.SelectedProfile.UUID, new AuthProfileModel {
                          DisplayName = Username
                      } }
                },
                Properties = new List <AuthPropertyModel>
                {
                    authProperty
                }
            };

            LauncherProfileParser.AddNewAuthInfo(authInfo, uuid);

            return(result);
        }
Example #2
0
        public AuthResult Auth(bool userField)
        {
            var authProperty = new AuthPropertyModel
            {
                Name      = "preferredLanguage",
                ProfileId = "",
                UserId    = Guid.NewGuid().ToString("N"),
                Value     = "zh-cn"
            };

            var calcGuid = GuidHelper.GetGuidByName(Username).ToString("N");
            var result   = new AuthResult
            {
                AccessToken     = Guid.NewGuid().ToString("N"),
                AuthStatus      = AuthStatus.Succeeded,
                SelectedProfile = new ProfileInfoModel
                {
                    Name = Username,
                    Id   = calcGuid
                },
                User = new UserInfoModel
                {
                    Id         = calcGuid,
                    Properties = new List <PropertyModel>
                    {
                        new PropertyModel
                        {
                            Name  = authProperty.Name,
                            Value = authProperty.Value
                        }
                    }
                }
            };

            var authInfo = new AuthInfoModel
            {
                UserName = Username,
                Profiles = new Dictionary <string, AuthProfileModel>
                {
                    { result.SelectedProfile.Id, new AuthProfileModel {
                          DisplayName = Username
                      } }
                },
                Properties = new List <AuthPropertyModel>
                {
                    authProperty
                }
            };

            LauncherProfileParser.AddNewAuthInfo(authInfo, calcGuid);

            return(result);
        }