Skip to content

Commit d7ad559

Browse files
author
Andrei Sirotenko
committed
YCIAM-9515 oauth token deprecation
1 parent d61b1b5 commit d7ad559

File tree

11 files changed

+22
-37
lines changed

11 files changed

+22
-37
lines changed

README.md

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,10 @@ Need to automate your infrastructure or use services provided by Yandex.Cloud? W
1414
## Getting started
1515

1616
There are three options for authorization your requests:
17-
- [OAuth Token](https://cloud.yandex.com/en-ru/docs/iam/concepts/authorization/oauth-token)
1817
- [IAM token](https://cloud.yandex.com/en-ru/docs/iam/operations/iam-token/create)
1918
- [Metadata Service](https://cloud.yandex.com/en-ru/docs/compute/concepts/vm-metadata) (if you're executing code inside VMs or Functions
2019
running in Yandex.Cloud)
2120

22-
### OAuth Token
23-
24-
```typescript
25-
import { Session, cloudApi, serviceClients } from '@yandex-cloud/nodejs-sdk';
26-
27-
const { resourcemanager: { cloud_service: { ListCloudsRequest } } } = cloudApi;
28-
29-
// Initialize SDK with your token
30-
const session = new Session({ oauthToken: 'YOUR_TOKEN' });
31-
32-
// Create service client
33-
const cloudService = session.client(serviceClients.CloudServiceClient);
34-
35-
// Issue request (returns Promise)
36-
const response = await cloudService.list(ListCloudsRequest.fromPartial({
37-
pageSize: 100,
38-
}));
39-
```
4021

4122
### Metadata Service
4223

@@ -84,7 +65,7 @@ To run example scripts, you should execute the following commands:
8465
```bash
8566
cd examples
8667
npm i
87-
YC_OAUTH_TOKEN=... YC_FOLDER_ID=... npm run start path/to/example.ts
68+
YC_IAM_TOKEN=... YC_FOLDER_ID=... npm run start path/to/example.ts
8869
```
8970

9071
## Services

examples/ai-translate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { log } from './utils/logger';
55
const { ai: { translate_translation_service: { TranslateRequest, TranslateRequest_Format: Format } } } = cloudApi;
66

77
const TEXTS = ['NodeJS SDK examples', 'Powerful, but easy to use library'];
8-
const AUTH_TOKEN = getEnv('YC_OAUTH_TOKEN');
8+
const IAM_TOKEN = getEnv('YC_IAM_TOKEN');
99
const FOLDER_ID = getEnv('YC_FOLDER_ID');
1010

1111
(async () => {
12-
const session = new Session({ oauthToken: AUTH_TOKEN });
12+
const session = new Session({ iamToken: IAM_TOKEN });
1313
const client = session.client(serviceClients.TranslationServiceClient);
1414

1515
const response = await client.translate(TranslateRequest.fromPartial({

examples/compute-instance-create.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
import { getEnv } from './utils/get-env';
55
import { log } from './utils/logger';
66

7-
const AUTH_TOKEN = getEnv('YC_OAUTH_TOKEN');
7+
const IAM_TOKEN = getEnv('YC_IAM_TOKEN');
88
const FOLDER_ID = getEnv('YC_FOLDER_ID');
99
const TARGET_ZONE_ID = 'ru-central1-a';
1010

@@ -30,7 +30,7 @@ const {
3030
} = cloudApi;
3131

3232
(async () => {
33-
const session = new Session({ oauthToken: AUTH_TOKEN });
33+
const session = new Session({ iamToken: IAM_TOKEN });
3434
const imageClient = session.client(serviceClients.ComputeImageServiceClient);
3535
const instanceClient = session.client(serviceClients.InstanceServiceClient);
3636
const networkClient = session.client(serviceClients.NetworkServiceClient);

examples/functions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { getEnv } from './utils/get-env';
33
import { log } from './utils/logger';
44

55
const { serverless: { functions_function_service: { ListFunctionsRequest } } } = cloudApi;
6-
const AUTH_TOKEN = getEnv('YC_OAUTH_TOKEN');
6+
const IAM_TOKEN = getEnv('YC_IAM_TOKEN');
77
const FOLDER_ID = getEnv('YC_FOLDER_ID');
88

99
(async () => {
10-
const session = new Session({ oauthToken: AUTH_TOKEN });
10+
const session = new Session({ iamToken: IAM_TOKEN });
1111
const client = session.client(serviceClients.FunctionServiceClient);
1212

1313
const response = await client.list(ListFunctionsRequest.fromPartial({ folderId: FOLDER_ID }));

examples/iot-data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ const {
88
devices_registry_data_service: { PublishRegistryDataRequest },
99
},
1010
} = cloudApi;
11-
const AUTH_TOKEN = getEnv('YC_OAUTH_TOKEN');
11+
const IAM_TOKEN = getEnv('YC_IAM_TOKEN');
1212
const FOLDER_ID = getEnv('YC_FOLDER_ID');
1313

1414
(async () => {
15-
const session = new Session({ oauthToken: AUTH_TOKEN });
15+
const session = new Session({ iamToken: IAM_TOKEN });
1616
const registryClient = session.client(serviceClients.IotRegistryServiceClient);
1717
const dataClient = session.client(serviceClients.RegistryDataServiceClient);
1818

examples/kms.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ const {
1313
} = cloudApi;
1414

1515
(async () => {
16-
const authToken = getEnv('YC_OAUTH_TOKEN');
16+
const iamToken = getEnv('YC_IAM_TOKEN');
1717
const folderId = getEnv('YC_FOLDER_ID');
18-
const session = new Session({ oauthToken: authToken });
18+
const session = new Session({ iamToken: iamToken });
1919
const keyClient = session.client(serviceClients.SymmetricKeyServiceClient);
2020
const cryptoClient = session.client(serviceClients.SymmetricCryptoServiceClient);
2121

examples/resourcemanager-cloud-list.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { getEnv } from './utils/get-env';
33
import { log } from './utils/logger';
44

55
const { resourcemanager: { cloud_service: { ListCloudsRequest } } } = cloudApi;
6-
const AUTH_TOKEN = getEnv('YC_OAUTH_TOKEN');
6+
const IAM_TOKEN = getEnv('YC_IAM_TOKEN');
77

88
(async () => {
9-
const session = new Session({ oauthToken: AUTH_TOKEN });
9+
const session = new Session({ iamToken: IAM_TOKEN });
1010
const client = session.client(serviceClients.CloudServiceClient);
1111

1212
const response = await client.list(ListCloudsRequest.fromPartial({ pageSize: 200 }));

examples/storage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { getEnv } from './utils/get-env';
33
import { log } from './utils/logger';
44

55
const { storage: { bucket_service: { ListBucketsRequest } } } = cloudApi;
6-
const AUTH_TOKEN = getEnv('YC_OAUTH_TOKEN');
6+
const IAM_TOKEN = getEnv('YC_IAM_TOKEN');
77
const FOLDER_ID = getEnv('YC_FOLDER_ID');
88

99
(async () => {
10-
const session = new Session({ oauthToken: AUTH_TOKEN });
10+
const session = new Session({ iamToken: IAM_TOKEN });
1111
const client = session.client(serviceClients.BucketServiceClient);
1212

1313
const response = await client.list(ListBucketsRequest.fromPartial({ folderId: FOLDER_ID }));

examples/stream-stt/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ file.pipe(reader);
2828
reader.pipe(data);
2929

3030
(async () => {
31-
const authToken = getEnv('YC_OAUTH_TOKEN');
31+
const iamToken = getEnv('YC_IAM_TOKEN');
3232
const folderId = getEnv('YC_FOLDER_ID');
33-
const session = new Session({ oauthToken: authToken });
33+
const session = new Session({ iamToken: iamToken });
3434
const client = session.client(serviceClients.SttServiceClient);
3535

3636
async function* createRequest(): AsyncIterable<StreamingRecognitionRequest> {

src/session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const newTokenCreator = (config: SessionConfig): () => Promise<string> => {
3636
if (isOAuth(config)) {
3737
return () => {
3838
const iamEndpoint = getServiceClientEndpoint(serviceClients.IamTokenServiceClient);
39-
39+
console.warn("The OAuthToken credential provider is deprecated at Yandex Cloud. By the end of 2026 will be fully discontinued. Please consider to use another credetials provider.");
4040
return createIamToken(iamEndpoint, {
4141
yandexPassportOauthToken: config.oauthToken,
4242
});

0 commit comments

Comments
 (0)