Skip to content

Initial Setup v2.3.0

lkubis edited this page Apr 22, 2020 · 1 revision

Instalation

Run the following command from the package manager console to install Cassandra identity provider.

Install-Package AspNetCore.Identity.Cassandra

Create your own User and Role entities

[Table("users", Keyspace = "identity")]
public class ApplicationUser : CassandraIdentityUser
{
    public ApplicationUser()
        : base(Guid.NewGuid())
    {
        
    }
}

[Table("roles", Keyspace = "identity")]
public class ApplicationRole : CassandraIdentityRole
{
    public ApplicationRole()
        : base(Guid.NewGuid())
    {
        
    }
}

appsettings.json

In Cassandra root there are information about keyspace, replication options, port, and retryCount (number of attempts when connection to cluster)
ContactPoints contains collection of IP addresses of all available nodes
Query is transformed to CqlQueryOptions

{   
    "Cassandra": {
        "ContactPoints": [
            "127.0.0.1"
        ],
        "Port": 9042,
        "RetryCount": 3,
        "Credentials": {
            "UserName": "Cassandra",
            "Password": "Cassandra"
        },
        "KeyspaceName": "identity",
        "Replication": {
            "class": "NetworkTopologyStrategy",
            "datacenter1": "1"
        },
        "Query": {
            "ConsistencyLevel": "One",
            "TracingEnabled": true,
            "PageSize": 25
        }
    }
}

Startup

public void ConfigureServices(IServiceCollection services)
{    
    // Cassandra ISession and DbInitializer setup
    services.AddCassandra(Configuration);

    // Add custom Cassandra stores
    services.AddIdentity<ApplicationUser, ApplicationRole>()
        .AddCassandraErrorDescriber<CassandraErrorDescriber>()
        .UseCassandraStores<Cassandra.ISession>()
        .AddDefaultTokenProviders();
    
    // Other code omitted
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app.UseCassandra<ApplicationUser, ApplicationRole>();
}
Clone this wiki locally