diff --git a/README.md b/README.md index e5eb75a4..ab7710b4 100644 --- a/README.md +++ b/README.md @@ -14,29 +14,10 @@ Need to automate your infrastructure or use services provided by Yandex.Cloud? W ## Getting started There are three options for authorization your requests: -- [OAuth Token](https://cloud.yandex.com/en-ru/docs/iam/concepts/authorization/oauth-token) - [IAM token](https://cloud.yandex.com/en-ru/docs/iam/operations/iam-token/create) - [Metadata Service](https://cloud.yandex.com/en-ru/docs/compute/concepts/vm-metadata) (if you're executing code inside VMs or Functions running in Yandex.Cloud) -### OAuth Token - -```typescript -import { Session, cloudApi, serviceClients } from '@yandex-cloud/nodejs-sdk'; - -const { resourcemanager: { cloud_service: { ListCloudsRequest } } } = cloudApi; - -// Initialize SDK with your token -const session = new Session({ oauthToken: 'YOUR_TOKEN' }); - -// Create service client -const cloudService = session.client(serviceClients.CloudServiceClient); - -// Issue request (returns Promise) -const response = await cloudService.list(ListCloudsRequest.fromPartial({ - pageSize: 100, -})); -``` ### Metadata Service @@ -84,7 +65,7 @@ To run example scripts, you should execute the following commands: ```bash cd examples npm i -YC_OAUTH_TOKEN=... YC_FOLDER_ID=... npm run start path/to/example.ts +YC_IAM_TOKEN=... YC_FOLDER_ID=... npm run start path/to/example.ts ``` ## Services diff --git a/examples/ai-translate.ts b/examples/ai-translate.ts index 04a6cb21..e8f204b3 100644 --- a/examples/ai-translate.ts +++ b/examples/ai-translate.ts @@ -5,11 +5,11 @@ import { log } from './utils/logger'; const { ai: { translate_translation_service: { TranslateRequest, TranslateRequest_Format: Format } } } = cloudApi; const TEXTS = ['NodeJS SDK examples', 'Powerful, but easy to use library']; -const AUTH_TOKEN = getEnv('YC_OAUTH_TOKEN'); +const IAM_TOKEN = getEnv('YC_IAM_TOKEN'); const FOLDER_ID = getEnv('YC_FOLDER_ID'); (async () => { - const session = new Session({ oauthToken: AUTH_TOKEN }); + const session = new Session({ iamToken: IAM_TOKEN }); const client = session.client(serviceClients.TranslationServiceClient); const response = await client.translate(TranslateRequest.fromPartial({ diff --git a/examples/compute-instance-create.ts b/examples/compute-instance-create.ts index edb31796..c8a86a55 100644 --- a/examples/compute-instance-create.ts +++ b/examples/compute-instance-create.ts @@ -4,7 +4,7 @@ import { import { getEnv } from './utils/get-env'; import { log } from './utils/logger'; -const AUTH_TOKEN = getEnv('YC_OAUTH_TOKEN'); +const IAM_TOKEN = getEnv('YC_IAM_TOKEN'); const FOLDER_ID = getEnv('YC_FOLDER_ID'); const TARGET_ZONE_ID = 'ru-central1-a'; @@ -30,7 +30,7 @@ const { } = cloudApi; (async () => { - const session = new Session({ oauthToken: AUTH_TOKEN }); + const session = new Session({ iamToken: IAM_TOKEN }); const imageClient = session.client(serviceClients.ComputeImageServiceClient); const instanceClient = session.client(serviceClients.InstanceServiceClient); const networkClient = session.client(serviceClients.NetworkServiceClient); diff --git a/examples/functions.ts b/examples/functions.ts index 243f54a4..6a26a8a5 100644 --- a/examples/functions.ts +++ b/examples/functions.ts @@ -3,11 +3,11 @@ import { getEnv } from './utils/get-env'; import { log } from './utils/logger'; const { serverless: { functions_function_service: { ListFunctionsRequest } } } = cloudApi; -const AUTH_TOKEN = getEnv('YC_OAUTH_TOKEN'); +const IAM_TOKEN = getEnv('YC_IAM_TOKEN'); const FOLDER_ID = getEnv('YC_FOLDER_ID'); (async () => { - const session = new Session({ oauthToken: AUTH_TOKEN }); + const session = new Session({ iamToken: IAM_TOKEN }); const client = session.client(serviceClients.FunctionServiceClient); const response = await client.list(ListFunctionsRequest.fromPartial({ folderId: FOLDER_ID })); diff --git a/examples/iot-data.ts b/examples/iot-data.ts index b44feae2..c27a0377 100644 --- a/examples/iot-data.ts +++ b/examples/iot-data.ts @@ -8,11 +8,11 @@ const { devices_registry_data_service: { PublishRegistryDataRequest }, }, } = cloudApi; -const AUTH_TOKEN = getEnv('YC_OAUTH_TOKEN'); +const IAM_TOKEN = getEnv('YC_IAM_TOKEN'); const FOLDER_ID = getEnv('YC_FOLDER_ID'); (async () => { - const session = new Session({ oauthToken: AUTH_TOKEN }); + const session = new Session({ iamToken: IAM_TOKEN }); const registryClient = session.client(serviceClients.IotRegistryServiceClient); const dataClient = session.client(serviceClients.RegistryDataServiceClient); diff --git a/examples/kms.ts b/examples/kms.ts index d2d886eb..82294659 100644 --- a/examples/kms.ts +++ b/examples/kms.ts @@ -13,9 +13,9 @@ const { } = cloudApi; (async () => { - const authToken = getEnv('YC_OAUTH_TOKEN'); + const iamToken = getEnv('YC_IAM_TOKEN'); const folderId = getEnv('YC_FOLDER_ID'); - const session = new Session({ oauthToken: authToken }); + const session = new Session({ iamToken: iamToken }); const keyClient = session.client(serviceClients.SymmetricKeyServiceClient); const cryptoClient = session.client(serviceClients.SymmetricCryptoServiceClient); diff --git a/examples/resourcemanager-cloud-list.ts b/examples/resourcemanager-cloud-list.ts index 07eb3b2e..523a3bc6 100644 --- a/examples/resourcemanager-cloud-list.ts +++ b/examples/resourcemanager-cloud-list.ts @@ -3,10 +3,10 @@ import { getEnv } from './utils/get-env'; import { log } from './utils/logger'; const { resourcemanager: { cloud_service: { ListCloudsRequest } } } = cloudApi; -const AUTH_TOKEN = getEnv('YC_OAUTH_TOKEN'); +const IAM_TOKEN = getEnv('YC_IAM_TOKEN'); (async () => { - const session = new Session({ oauthToken: AUTH_TOKEN }); + const session = new Session({ iamToken: IAM_TOKEN }); const client = session.client(serviceClients.CloudServiceClient); const response = await client.list(ListCloudsRequest.fromPartial({ pageSize: 200 })); diff --git a/examples/storage.ts b/examples/storage.ts index ea28eeb2..c20199d4 100644 --- a/examples/storage.ts +++ b/examples/storage.ts @@ -3,11 +3,11 @@ import { getEnv } from './utils/get-env'; import { log } from './utils/logger'; const { storage: { bucket_service: { ListBucketsRequest } } } = cloudApi; -const AUTH_TOKEN = getEnv('YC_OAUTH_TOKEN'); +const IAM_TOKEN = getEnv('YC_IAM_TOKEN'); const FOLDER_ID = getEnv('YC_FOLDER_ID'); (async () => { - const session = new Session({ oauthToken: AUTH_TOKEN }); + const session = new Session({ iamToken: IAM_TOKEN }); const client = session.client(serviceClients.BucketServiceClient); const response = await client.list(ListBucketsRequest.fromPartial({ folderId: FOLDER_ID })); diff --git a/examples/stream-stt/index.ts b/examples/stream-stt/index.ts index 5a1058e4..996601e4 100644 --- a/examples/stream-stt/index.ts +++ b/examples/stream-stt/index.ts @@ -28,9 +28,9 @@ file.pipe(reader); reader.pipe(data); (async () => { - const authToken = getEnv('YC_OAUTH_TOKEN'); + const iamToken = getEnv('YC_IAM_TOKEN'); const folderId = getEnv('YC_FOLDER_ID'); - const session = new Session({ oauthToken: authToken }); + const session = new Session({ iamToken: iamToken }); const client = session.client(serviceClients.SttServiceClient); async function* createRequest(): AsyncIterable { diff --git a/src/session.ts b/src/session.ts index c88cf599..0755abcc 100644 --- a/src/session.ts +++ b/src/session.ts @@ -37,6 +37,10 @@ const newTokenCreator = (config: SessionConfig): () => Promise => { return () => { const iamEndpoint = getServiceClientEndpoint(serviceClients.IamTokenServiceClient); + console.warn( + 'By the end of 2026 OAuthToken will be discontinued at Yandex Cloud. Please consider to use another credetials provider.', + ); + return createIamToken(iamEndpoint, { yandexPassportOauthToken: config.oauthToken, }); diff --git a/src/types.ts b/src/types.ts index 2a902367..ca80af9d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -47,6 +47,10 @@ export interface GenericCredentialsConfig { headers?: Record; } +/** + * @deprecated By the end of 2026, the use of oauth tokens in the Yandex cloud will be discontinued. + * Please consider to use another credentials provider. + */ export interface OAuthCredentialsConfig extends GenericCredentialsConfig { oauthToken: string; }