Exemple #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);
    }
Exemple #2
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);
    }