Authentication using a token
Note
The article is being updated.
Below are examples of the code for authentication using a token in different YDB SDKs.
Go
Java
1. package main
3. import (
4. "context"
5. "os"
7. "github.com/ydb-platform/ydb-go-sdk/v3"
8. )
10. func main() {
11. ctx, cancel := context.WithCancel(context.Background())
12. defer cancel()
13. db, err := ydb.Open(
14. ctx,
15. os.Getenv("YDB_CONNECTION_STRING"),
16. ydb.WithAccessTokenCredentials(os.Getenv("YDB_TOKEN")),
17. )
18. if err != nil {
19. panic(err)
20. }
21. defer func() {
22. _ = db.Close(ctx)
23. }()
24. }

1. public void work(String connectionString, String accessToken) {
2. AuthProvider authProvider = CloudAuthProvider.newAuthProvider(
3. IamTokenCredentialProvider.builder()
4. .token(accessToken)
5. .build()
6. );
8. GrpcTransport transport = GrpcTransport.forConnectionString(connectionString)
9. .withAuthProvider(authProvider)
10. .build();
12. TableClient tableClient = TableClient
13. .newClient(GrpcTableRpc.ownTransport(transport))
14. .build());
16. doWork(tableClient);
18. tableClient.close();
19. }

