---
sidebar_position: 4
slug: /dev/signin
---

# 98.4、登入信标验证

:::tip[说明]
登入信标，注入自定义参数，或者使用已有参数验证
```
//初始化
LinkerMessengerEntry.Initialize();
//在这里注入
LinkerMessengerEntry.AddService<MyClientSignInArgs>();
LinkerMessengerEntry.AddService<MyServerSignInArgs>();

//构建
LinkerMessengerEntry.Build();

SignInArgsTransfer signInArgsTransfer = LinkerMessengerEntry.GetService<SignInArgsTransfer>();
//可以删除默认的一些验证,group分组密码，machineId设备唯一编号，secretKey信标密钥，version版本验证
//signInArgsTransfer.RemoveArgs(new List<string>{ "group","machineId","secretKey","version" });

ICommonStore commonStore = LinkerMessengerEntry.GetService<ICommonStore>();
//客户端则添加客户端类
if((commonStore.Modes & CommonModes.Client) == CommonModes.Client)
{
    signInArgsTransfer.AddArgs(new List<ISignInArgs> { 
        LinkerMessengerEntry.GetService<MyClientSignInArgs>() 
    });
}
//服务端则添加服务端类
if((commonStore.Modes & CommonModes.Server) == CommonModes.Server)
{
    signInArgsTransfer.AddArgs(new List<ISignInArgs> { 
        LinkerMessengerEntry.GetService<MyServerSignInArgs>() 
    });
}

//运行
LinkerMessengerEntry.Setup();


/// <summary>
/// 客户端
/// </summary>
public sealed class MyClientSignInArgs : ISignInArgs
{
    public string Name => "mySigninArgs";
    /// <summary>
    /// 客户端调用
    /// </summary>
    /// <param name="host">登入的服务器</param>
    /// <param name="args">往这里面添加参数</param>
    /// <returns>返回不为空则为错误信息，中断登录操作</returns>
    public async Task<string> Invoke(string host, Dictionary<string, string> args)
    {
        args.Add("myArgs", "myArgs")
        await Task.CompletedTask;
        return string.Empty;
    }
    public async Task<string> Validate(SignInfo signInfo, SignCacheInfo cache)
    {
        await Task.CompletedTask;
        return string.Empty;
    }
}
/// <summary>
/// 服务端
/// </summary>
public sealed class MyServerSignInArgs : ISignInArgs
{
    public string Name => "mySigninArgs";
    public async Task<string> Invoke(string host, Dictionary<string, string> args)
    {
        await Task.CompletedTask;
        return string.Empty;
    }

    /// <summary>
    /// 服务端调用
    /// </summary>
    /// <param name="signInfo">本次登录参数</param>
    /// <param name="cache">之前的登录信息，如果以前登录过的话</param>
    /// <returns>返回不为空则为错误信息，登录失败</returns>
    public async Task<string> Validate(SignInfo signInfo, SignCacheInfo cache)
    {
        if (signInfo.Args.TryGetValue("myArgs", out string arg) == false)
        {
            return $"myArgs validate fail";
        }
        await Task.CompletedTask;
        return string.Empty;
    }
}
```
:::