Anonymous authentication
Note
The article is being updated.
Below are examples of the code for anonymous authentication in different YDB SDKs.
Go (native)
Go (database/sql)
Java
Node.js
By default, anonymous authentication is used.
You can explicitly enable anonymous authentication as follows:
package main
import (
"context"
"github.com/ydb-platform/ydb-go-sdk/v3"
)
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
db, err := ydb.Open(ctx,
os.Getenv("YDB_CONNECTION_STRING"),
ydb.WithAnonymousCredentials(),
)
if err != nil {
panic(err)
}
defer db.Close(ctx)
...
}
By default, anonymous authentication is used.
You can explicitly enable anonymous authentication as follows:
package main
import (
"context"
"database/sql"
"os"
"github.com/ydb-platform/ydb-go-sdk/v3"
)
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
nativeDriver, err := ydb.Open(ctx,
os.Getenv("YDB_CONNECTION_STRING"),
ydb.WithAnonymousCredentials(),
)
if err != nil {
panic(err)
}
defer nativeDriver.Close(ctx)
connector, err := ydb.Connector(nativeDriver)
if err != nil {
panic(err)
}
db := sql.OpenDB(connector)
defer db.Close()
...
}
public void work(String connectionString) {
AuthProvider authProvider = NopAuthProvider.INSTANCE;
GrpcTransport transport = GrpcTransport.forConnectionString(connectionString)
.withAuthProvider(authProvider)
.build());
TableClient tableClient = TableClient.newClient(transport).build();
doWork(tableClient);
tableClient.close();
transport.close();
}
import { Driver, AnonymousAuthService } from 'ydb-sdk';
export async function connect(endpoint: string, database: string) {
const authService = new AnonymousAuthService();
const driver = new Driver({endpoint, database, authService});
const timeout = 10000;
if (!await driver.ready(timeout)) {
console.log(`Driver has not become ready in ${timeout}ms!`);
process.exit(1);
}
console.log('Driver connected')
return driver
}