Exemplo n.º 1
0
        public static void AddRequestTokenCommand(this CommandLineApplication app, ConfigFile config)
        {
            app.Command("tokenrequest", cmd =>
            {
                var optionUser = cmd.Option("-u|--user <USERID>", "Required. A Afas username (12345.username) or emailaddress.", CommandOptionType.SingleValue)
                                 .IsRequired();

                cmd.Description = "Request a token for a specified user.";
                cmd.OnValidate((ctx) =>
                {
                    if ((config == null) || (!config.IsValidForOtp))
                    {
                        return(new ValidationResult("A valid configuration (with ApiKey and EnviromentKey) could not be found. Use [config]."));
                    }
                    return(ValidationResult.Success);
                });

                cmd.OnExecuteAsync(async(cancellationtoken) =>
                {
                    AfasOtpClient client = new AfasOtpClient(config.MemberNumber, config.ApiKey
                                                             , config.EnvironmentKey, (Environments)config.Environment);

                    var x = await client.GetOtpTokenRequest(optionUser.Value());
                });
            });
        }
Exemplo n.º 2
0
        static async Task <int> Main(string[] args)
        {
            //If you don't have a token , you can generate one
            var otpclient = new AfasOtpClient(12345, "api-key", "environment-key");

            //Request the otp valdiation code, which is send by mail by Afas.
            await otpclient.GetOtpTokenRequest("*****@*****.**");

            //Assume you received validation code 123456 by mail, you can request a token.
            var token = await otpclient.GetOtpTokenValidation("*****@*****.**", "123456");


            //With a token, you can start working with the AfasClient
            var client = new AfasClient(00000, "token", Environments.Test);


            var session = client.GetSessionInfo();

            Console.WriteLine($"ConnectorName: {session.Info.ApplicationName}");
            Console.WriteLine($"EnvironmentID: {session.Info.EnvironmentID}");
            Console.WriteLine($"Group        : {session.Info.Group}");


            //overview of GetConnectors.
            foreach (var conn in session.GetConnectors)
            {
                Console.WriteLine($"{conn.Id} - {conn.Description}");
            }

            //Request a file
            var fileInfo = await client.GetFileAsync("test", "invoice001.pdf");

            if (fileInfo != null)
            {
                var bytes = Convert.FromBase64String(fileInfo.FileDataBase64);
            }
            ;



            return(0);
        }
Exemplo n.º 3
0
        public static void AddActivateTokenCommand(this CommandLineApplication app, ConfigFile config)
        {
            app.Command("tokenactivate", cmd =>
            {
                var optionUser = cmd.Option("-u|--user <USERID>", "Required. A Afas username (12345.username) or emailaddress.", CommandOptionType.SingleValue)
                                 .IsRequired();

                var optionCode = cmd.Option("-c|--code <CODE>", "Required. The activationcode send by mail.", CommandOptionType.SingleValue)
                                 .IsRequired();

                cmd.Description = "Gets a token for the specified user and its activationcode ";
                cmd.OnValidate((ctx) =>
                {
                    if ((config == null) || (!config.IsValidForOtp))
                    {
                        return(new ValidationResult("A valid configuration (with ApiKey and EnviromentKey) could not be found. Use [config]."));
                    }
                    return(ValidationResult.Success);
                });
                cmd.OnExecuteAsync(async(cancellationtoken) =>
                {
                    AfasOtpClient client = new AfasOtpClient(config.MemberNumber, config.ApiKey
                                                             , config.EnvironmentKey, (Environments)config.Environment);

                    try
                    {
                        var token = await client.GetOtpTokenValidation(optionUser.Value(), optionCode.Value());
                        Console.WriteLine(token);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine();
                    }
                });
            });
        }