Beispiel #1
0
    private static int Execute(IReporter reporter, string projectPath, string id)
    {
        if (!DevJwtCliHelpers.GetProjectAndSecretsId(projectPath, reporter, out var project, out var userSecretsId))
        {
            return(1);
        }
        var jwtStore = new JwtStore(userSecretsId);

        if (!jwtStore.Jwts.ContainsKey(id))
        {
            reporter.Error(Resources.FormatRemoveCommand_NoJwtFound(id));
            return(1);
        }

        var jwt = jwtStore.Jwts[id];
        var appsettingsFilePath = Path.Combine(Path.GetDirectoryName(project), "appsettings.Development.json");

        JwtAuthenticationSchemeSettings.RemoveScheme(appsettingsFilePath, jwt.Scheme);
        jwtStore.Jwts.Remove(id);
        jwtStore.Save();

        reporter.Output(Resources.FormatRemoveCommand_Confirmed(id));

        return(0);
    }
Beispiel #2
0
    private static int Execute(IReporter reporter, string projectPath, string id, bool showFull)
    {
        if (!DevJwtCliHelpers.GetProjectAndSecretsId(projectPath, reporter, out var _, out var userSecretsId))
        {
            return(1);
        }
        var jwtStore = new JwtStore(userSecretsId);

        if (!jwtStore.Jwts.TryGetValue(id, out var jwt))
        {
            reporter.Output(Resources.FormatPrintCommand_NoJwtFound(id));
            return(1);
        }

        reporter.Output(Resources.FormatPrintCommand_Confirmed(id));
        JwtSecurityToken fullToken;

        if (showFull)
        {
            fullToken = JwtIssuer.Extract(jwt.Token);
            DevJwtCliHelpers.PrintJwt(reporter, jwt, fullToken);
        }

        return(0);
    }
Beispiel #3
0
    private static int Execute(IReporter reporter, string projectPath, bool force)
    {
        if (!DevJwtCliHelpers.GetProjectAndSecretsId(projectPath, reporter, out var project, out var userSecretsId))
        {
            return(1);
        }
        var jwtStore = new JwtStore(userSecretsId);
        var count    = jwtStore.Jwts.Count;

        if (count == 0)
        {
            reporter.Output(Resources.FormatClearCommand_NoJwtsRemoved(project));
            return(0);
        }

        if (!force)
        {
            reporter.Output(Resources.ClearCommand_Permission);
            reporter.Output("[Y]es / [N]o");
            if (Console.ReadLine().Trim().ToUpperInvariant() != "Y")
            {
                reporter.Output(Resources.ClearCommand_Canceled);
                return(0);
            }
        }

        var appsettingsFilePath = Path.Combine(Path.GetDirectoryName(project), "appsettings.Development.json");

        foreach (var jwt in jwtStore.Jwts)
        {
            JwtAuthenticationSchemeSettings.RemoveScheme(appsettingsFilePath, jwt.Value.Scheme);
        }

        jwtStore.Jwts.Clear();
        jwtStore.Save();

        reporter.Output(Resources.FormatClearCommand_Confirmed(count, project));

        return(0);
    }
Beispiel #4
0
    private static int Execute(IReporter reporter, string projectPath, bool showTokens)
    {
        if (!DevJwtCliHelpers.GetProjectAndSecretsId(projectPath, reporter, out var project, out var userSecretsId))
        {
            return(1);
        }
        var jwtStore = new JwtStore(userSecretsId);

        reporter.Output(Resources.FormatListCommand_Project(project));
        reporter.Output(Resources.FormatListCommand_UserSecretsId(userSecretsId));

        if (jwtStore.Jwts is { Count : > 0 } jwts)
        {
            var table = new ConsoleTable(reporter);
            table.AddColumns(Resources.JwtPrint_Id, Resources.JwtPrint_Scheme, Resources.JwtPrint_Audiences, Resources.JwtPrint_IssuedOn, Resources.JwtPrint_ExpiresOn);

            if (showTokens)
            {
                table.AddColumns(Resources.JwtPrint_Token);
            }

            foreach (var jwtRow in jwts)
            {
                var jwt = jwtRow.Value;
                if (showTokens)
                {
                    table.AddRow(jwt.Id, jwt.Scheme, jwt.Audience, jwt.Issued.ToString("O"), jwt.Expires.ToString("O"), jwt.Token);
                }
                else
                {
                    table.AddRow(jwt.Id, jwt.Scheme, jwt.Audience, jwt.Issued.ToString("O"), jwt.Expires.ToString("O"));
                }
            }

            table.Write();
        }