Connection and authentication
immudb runs on port 3323 as the default. The code samples below illustrate how to connect your client to the server and authenticate using default options and the default username and password. You can modify defaults on the immudb server in immudb.toml
in the config folder.
The Login method returns a token required for all interactions with the server.
c, err := client.NewImmuClient(client.DefaultOptions())
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
// login with default username and password and storing a token
lr , err := c.Login(ctx, []byte(`immudb`), []byte(`immudb2`))
if err != nil {
log.Fatal(err)
}
// set up an authenticated context that will be required in future operations
md := metadata.Pairs("authorization", lr.Token)
ctx = metadata.NewOutgoingContext(context.Background(), md)
Under the hood, during login
, a token is being retrieved from the server, stored in memory and reused for subsequent operations.
The state is internally used for doing verified operations (such as verifiedSet or verifiedGet).
// Setting the "store" where the internal states are being persisted.
FileImmuStateHolder stateHolder = FileImmuStateHolder.newBuilder()
.withStatesFolder("immu_states")
.build();
// Creating an new ImmuClient instance.
ImmuClient immuClient = ImmuClient.newBuilder()
.withStateHolder(stateHolder)
.withServerUrl("localhost")
.withServerPort(3322)
.build();
// Login with default credentials.
immuClient.login("immudb", "immudb");
This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Python sdk github project (opens new window)
This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Node.js sdk github project (opens new window)
This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on .Net sdk github project (opens new window)
If you’re using another development language, please read up on our immugw (opens new window) option.
Mutual TLS
To enable mutual authentication, a certificate chain must be provided to both the server and client. That will cause each to authenticate with the other simultaneously. In order to generate certs, use the openssl tool: generate.sh (opens new window).
./generate.sh localhost mysecretpassword
This generates a list of folders containing certificates and private keys to set up a mTLS connection.
client, err := c.NewImmuClient(
c.DefaultOptions().WithMTLsOptions(
c.MTLsOptions{}.WithCertificate("{path-to-immudb-src-folder}/tools/mtls/4_client/certs/localhost.cert.pem").
WithPkey("{path-to-immudb-src-folder}/tools/mtls/4_client/private/localhost.key.pem").
WithClientCAs("{path-to-immudb-src-folder}/tools/mtls/2_intermediate/certs/ca-chain.cert.pem").
WithServername("localhost"),
).
WithMTLs(true),
)
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
// login with default username and password
lr , err := client.Login(ctx, []byte(`immudb`), []byte(`immudb`))
This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Java sdk github project (opens new window)
This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Python sdk github project (opens new window)
import ImmudbClient from 'immudb-node'
import Parameters from 'immudb-node/types/parameters'
const IMMUDB_HOST = '127.0.0.1'
const IMMUDB_PORT = '3322'
const IMMUDB_USER = 'immudb'
const IMMUDB_PWD = 'immudb'
const cl = new ImmudbClient({ host: IMMUDB_HOST, port: IMMUDB_PORT });
(async () => {
const loginReq: Parameters.Login = { user: IMMUDB_USER, password: IMMUDB_PWD }
const loginRes = await cl.login(loginReq)
console.log('success: login:', loginRes)
})()
This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on .Net sdk github project (opens new window)
If you’re using another development language, please read up on our immugw (opens new window) option.
Disable authentication
You also have the option to run immudb with authentication disabled. However, without authentication enabled, it’s not possible to connect to a server already configured with databases and user permissions. If a valid token is present, authentication is enabled by default.
client, err := c.NewImmuClient(
c.DefaultOptions().WithAuth(false),
)
if err != nil {
log.Fatal(err)
}
vi, err := client.VerifiedSet(ctx, []byte(`immudb`), []byte(`hello world`))
if err != nil {
log.Fatal(err)
}
FileImmuStateHolder stateHolder = FileImmuStateHolder.newBuilder()
.withStatesFolder("immu_states")
.build();
ImmuClient immuClient = ImmuClient.newBuilder()
.withStateHolder(stateHolder)
.withServerUrl("localhost")
.withServerPort(3322)
.withAuth(false) // No authentication is needed.
.build();
try {
immuClient.set(key, val);
} catch (CorruptedDataException e) {
// ...
}
This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Python sdk github project (opens new window)
This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Node.js sdk github project (opens new window)
This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on .Net sdk github project (opens new window)
If you’re using another development language, please read up on our immugw (opens new window) option.