API 키를 사용하여 IBM Cloud IAM 토큰 생성
IAM API 키 또는 서비스 ID의 API 키를 사용하여 IBM Cloud® Identity and Access Management (IAM) 토큰을 생성합니다. IBM Cloud 할당된 IAM 역할에 의해 권한이 부여된 사용자만 API에 액세스할 수 있습니다. API를 호출 중인 각 사용자는 인증하기 위해 API에 대한 인증 정보를 전달해야 합니다.
IAM 토큰 생성
IBM Cloud API 키 또는 서비스 ID의 API 키를 사용하여 IAM 토큰을 생성할 수 있습니다. API 키는 API 키 값을 유실하거나 계정에서 API 키를 삭제하지 않으면 재사용할 수 있는 영구 인증 정보입니다. 또한 이 프로세스는 다른 IBM Cloud 서비스와 작업해야 하는 애플리케이션을 개발 중인 경우에도 사용됩니다. IBM Cloud의 각 서비스에 전달될 액세스 토큰을 가져오려면 서비스 ID API 키를 사용해야 합니다.
액세스 토큰은 최소한 1시간 후에 만료되는 임시 인증 정보입니다. 획득한 토큰이 만료된 후 IBM Cloud 또는 서비스 API를 계속 호출하려면 새 토큰을 생성해야 하며 모든 계정 내에서 지정된 액세스 레벨에 의해 허용되는 조치만 수행할 수 있습니다. API 응답에서 응답 특성 expires_in을 사용하여 특정 액세스 토큰이 유효한 기간을 식별할 수 있습니다.
API 키를 사용하여 IAM 토큰 생성
API 키를 사용하여 프로그래밍 방식으로 IAM 토큰을 생성하려면 다음 샘플 요청에 표시된 대로 IAM 신원 서비스 API 또는 SDK를 호출합니다.
curl -X POST 'https://iam.cloud.ibm.com/identity/token' -H 'Content-Type: application/x-www-form-urlencoded' -d 'grant_type=urn:ibm:params:oauth:grant-type:apikey&apikey=MY_APIKEY'
import com.ibm.cloud.sdk.core.security.IamAuthenticator;
import <sdk_base_package>.ExampleService.v1.ExampleService;
...
// Create the authenticator.
IamAuthenticator authenticator = new IamAuthenticator.Builder()
.apikey("myapikey")
.build();
// Create the service instance.
ExampleService service = new ExampleService(authenticator);
// 'service' can now be used to invoke operations.
const ExampleServiceV1 = require('mysdk/example-service/v1');
const { IamAuthenticator } = require('mysdk/auth');
const authenticator = new IamAuthenticator({
apikey: '<iam-api-key>',
});
const myService = new ExampleServiceV1({
authenticator,
});
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
from <sdk-package-name>.example_service_v1 import *
# Create the authenticator.
authenticator = IAMAuthenticator('myapikey')
# Construct the service instance.
service = ExampleServiceV1(authenticator=authenticator)
# Use 'service' to invoke operations.
import {
"github.com/IBM/go-sdk-core/v5/core"
"<appropriate-git-repo-url>/exampleservicev1"
}
...
// Create the authenticator.
authenticator := &core.IamAuthenticator{
ApiKey: "myapikey",
}
// Create the service options struct.
options := &exampleservicev1.ExampleServiceV1Options{
Authenticator: authenticator,
}
// Construct the service instance.
service := exampleservicev1.NewExampleServiceV1(options)
// 'service' can now be used to invoke operations.
예상된 응답
{
"access_token": "eyJhbGciOiJIUz......sgrKIi8hdFs",
"refresh_token": "not_supported",
"ims_user_id": 118...90,
"token_type": "Bearer",
"expires_in": 3600,
"expiration": 1473188353,
"scope": "ibm openid"
}
자세한 정보는 IAM ID 서비스 API를 참조하십시오.
자세한 내용은 Java SDK를 참조하세요.
자세한 내용은 SDK를 참조하세요.
자세한 내용은 Python SDK를 참조하세요.
자세한 내용은 Go SDK를 참조하세요.
IAM 토큰은 최대 60분 동안 유효하며 변경될 수 있습니다. 토큰이 만기되면 새로 작성해야 합니다. 방금 작성한 IAM 토큰의 만기에 대해 expires_in 특성을 사용하십시오.