Go 1.11은 지원이 종료되었으며 2026년 1월 31일에 지원 중단됩니다. 지원 중단 후에는 조직에서 이전에 조직 정책을 사용하여 레거시 런타임의 배포를 다시 사용 설정한 경우에도 Go 1.11 애플리케이션을 배포할 수 없습니다. 기존 Go 1.11 애플리케이션은 지원 중단 날짜 이후에도 계속 실행되고 트래픽을 수신합니다. 지원되는 최신 Go 버전으로 마이그레이션하는 것이 좋습니다.
REGION_ID는 앱을 만들 때 선택한 리전을 기준으로 Google에서 할당하는 축약된 코드입니다. 일부 리전 ID는 일반적으로 사용되는 국가 및 주/도 코드와 비슷하게 표시될 수 있지만 코드는 국가 또는 주/도와 일치하지 않습니다. 2020년 2월 이후에 생성된 앱의 경우 REGION_ID.r이 App Engine URL에 포함됩니다. 이 날짜 이전에 만든 기존 앱의 경우 URL에서 리전 ID는 선택사항입니다.
App Identity API를 사용하면 애플리케이션이 스스로의 애플리케이션 ID(다른 명칭은 프로젝트 ID)를 확인할 수 있습니다. App Engine 애플리케이션은 이 ID를 사용하여 다른 App Engine 앱, Google API, 서드 파티 애플리케이션 및 서비스에 자신의 ID를 알릴 수 있습니다. 애플리케이션 ID는 URL 또는 이메일 주소를 생성하거나 런타임을 결정하는 데 사용될 수도 있습니다.
프로젝트 ID 가져오기
프로젝트 ID는 appengine.AppID 함수를 사용하여 확인할 수 있습니다.
애플리케이션 호스트 이름 가져오기
기본적으로 App Engine 앱은 https://PROJECT_ID.REGION_ID.r.appspot.com 형식의 URL에서 제공되며, 여기서 프로젝트 ID는 호스트 이름의 일부입니다.
앱이 커스텀 도메인에서 제공될 때는 전체 호스트 이름 구성요소를 검색해야 할 수 있습니다. appengine.DefaultVersionHostname 함수를 사용하여 이 작업을 수행할 수 있습니다.
다른 App Engine 앱에 ID 알림
App Engine 앱에 요청하는 App Engine 앱의 ID를 확인하려면 요청 헤더 X-Appengine-Inbound-Appid를 사용하면 됩니다. 이 헤더는 URLFetch 서비스를 통해 요청에 추가되며 사용자가 수정할 수 없으므로 이 헤더가 있으면 요청하는 애플리케이션의 프로젝트 ID라고 신뢰할 수 있습니다.
요구사항:
앱의 appspot.com 도메인에 대한 호출에만 X-Appengine-Inbound-Appid 헤더가 포함됩니다. 커스텀 도메인에 대한 호출은 헤더를 포함하지 않습니다.
애플리케이션 핸들러에서 X-Appengine-Inbound-Appid 헤더를 읽고 요청을 실행할 수 있는 ID 목록과 비교하여 수신 ID를 확인할 수 있습니다.
Google API에 ID 알림
Google API는 인증 및 승인에 OAuth 2.0 프로토콜을 사용합니다. App Identity API는 애플리케이션 자체에서 요청을 보냈음을 알리는 데 사용 가능한 OAuth 토큰을 만들 수 있습니다. appengine.AccessToken 함수는 특정 범위 또는 범위 목록의 액세스 토큰을 반환합니다. 이 토큰을 호출의 HTTP 헤더에 설정하면 호출하는 애플리케이션을 식별할 수 있습니다.
다음 예시에서는 App Identity API를 사용하여 Google URL Shortener API에 REST 호출을 보내는 방법을 보여줍니다.
import("context""net/http""google.golang.org/appengine/urlfetch""golang.org/x/oauth2""golang.org/x/oauth2/google"urlshortener"google.golang.org/api/urlshortener/v1")// shortenURL returns a short URL which redirects to the provided url,// using Google's urlshortener API.funcshortenURL(ctxcontext.Context,urlstring)(string,error){transport:=&oauth2.Transport{Source:google.AppEngineTokenSource(ctx,urlshortener.UrlshortenerScope),Base:&urlfetch.Transport{Context:ctx},}client:=&http.Client{Transport:transport}svc,err:=urlshortener.New(client)iferr!=nil{return"",err}resp,err:=svc.Url.Insert(&urlshortener.Url{LongUrl:url}).Do()iferr!=nil{return"",err}returnresp.Id,nil}
애플리케이션의 ID는 서비스 계정 이름(일반적으로 applicationid@appspot.gserviceaccount.com)으로 표시됩니다. appengine.ServiceAccount 함수를 사용하여 정확한 값을 가져올 수 있습니다.
ACL을 제공하는 서비스의 경우 이 계정 액세스 권한을 부여하여 애플리케이션 액세스 권한을 부여할 수 있습니다.
서드 파티 서비스에 ID 알림
AccessToken으로 생성된 토큰은 Google 서비스에서만 작동합니다. 그러나 내부적인 서명 기술을 사용하면 다른 서비스에 애플리케이션의 ID를 알릴 수 있습니다. appengine.SignBytes 함수는 애플리케이션에 고유한 비공개 키를 사용하여 바이트에 서명하고 appengine.PublicCertificates 함수는 서명을 검증하는 데 사용할 수 있는 인증서를 반환합니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[[["\u003cp\u003eThe \u003ccode\u003eREGION_ID\u003c/code\u003e is a Google-assigned code based on the region selected during app creation, included in App Engine URLs for apps created after February 2020, but it does not directly correspond to specific countries or provinces.\u003c/p\u003e\n"],["\u003cp\u003eThe App Identity API allows an application to discover its project ID and assert its identity to other App Engine apps, Google APIs, and third-party services.\u003c/p\u003e\n"],["\u003cp\u003eApp Engine apps are typically served from URLs in the form \u003ccode\u003ehttps://PROJECT_ID.REGION_ID.r.appspot.com\u003c/code\u003e, with the project ID being a part of the hostname.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eX-Appengine-Inbound-Appid\u003c/code\u003e request header can be used to verify the identity of an App Engine app making a request, but this header is only present in calls made to the app's \u003ccode\u003eappspot.com\u003c/code\u003e domain.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eappengine.AccessToken\u003c/code\u003e function can be used to generate OAuth tokens for asserting identity to Google APIs, and the \u003ccode\u003eappengine.SignBytes\u003c/code\u003e function can be used to assert identity to third-party services.\u003c/p\u003e\n"]]],[],null,["# App Identity API for legacy bundled services\n\n### Region ID\n\nThe \u003cvar translate=\"no\"\u003eREGION_ID\u003c/var\u003e is an abbreviated code that Google assigns\nbased on the region you select when you create your app. The code does not\ncorrespond to a country or province, even though some region IDs may appear\nsimilar to commonly used country and province codes. For apps created after\nFebruary 2020, \u003cvar translate=\"no\"\u003eREGION_ID\u003c/var\u003e`.r` is included in\nApp Engine URLs. For existing apps created before this date, the\nregion ID is optional in the URL.\n\nLearn more\n[about region IDs](/appengine/docs/legacy/standard/go111/how-requests-are-routed#region-id). \nOK\n\nThe App Identity API lets an application discover its application ID (also\ncalled the [project ID](https://support.google.com/cloud/answer/6158840)). Using\nthe ID, an App Engine application can assert its identity to other App Engine\nApps, Google APIs, and third-party applications and services. The\napplication ID can also be used to generate a URL or email address, or to make\na run-time decision.\n| This API is supported for first-generation runtimes and can be used when [upgrading to corresponding second-generation runtimes](/appengine/docs/standard/\n| go\n| /services/access). If you are updating to the App Engine Go 1.12+ runtime, refer to the [migration guide](/appengine/migration-center/standard/migrate-to-second-gen/go-differences) to learn about your migration options for legacy bundled services.\n\nGetting the project ID\n----------------------\n\nThe project ID can be found using the\n\n\n`appengine.AppID` function.\n\n\nGetting the application hostname\n--------------------------------\n\nBy default, App Engine apps are served from URLs in the form\n\n`https://`\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e`.`\u003cvar translate=\"no\"\u003e\u003ca href=\"#appengine-urls\" style=\"border-bottom: 1px dotted #999\" class=\"devsite-dialog-button\" data-modal-dialog-id=\"regional_url\" track-type=\"progressiveHelp\" track-name=\"modalHelp\" track-metadata-goal=\"regionalURL\"\u003eREGION_ID\u003c/a\u003e\u003c/var\u003e`.r.appspot.com`, where the project ID is part of the hostname.\nIf an app is served from a custom domain, it may be necessary to retrieve the\nentire hostname component. You can do this using the `appengine.DefaultVersionHostname` function.\n\nAsserting identity to other App Engine apps\n-------------------------------------------\n\nIf you want to determine the identity of the App Engine app that is making a\nrequest to your App Engine app, you can use the request header\n`X-Appengine-Inbound-Appid`. This header is added to the request by the URLFetch\nservice and is not user modifiable, so it safely indicates the requesting\napplication's project ID, if present.\n\n**Requirements**:\n\n- Only calls made to your app's `appspot.com` domain will contain the `X-Appengine-Inbound-Appid` header. Calls to custom domains do not contain the header.\n\nIn your application handler, you can check the incoming ID by reading the\n`X-Appengine-Inbound-Appid` header and comparing it to a list of IDs allowed\nto make requests.\n\nAsserting identity to Google APIs\n---------------------------------\n\nGoogle APIs use the OAuth 2.0 protocol for [authentication and\nauthorization](https://developers.google.com/identity/protocols/OAuth2). The\nApp Identity API can create OAuth tokens that can be used to assert that the\nsource of a request is the application itself. The `appengine.AccessToken` function\nreturns an access token for a scope, or list of scopes. This token can then be\nset in the HTTP headers of a call to identify the calling application.\nThe following example shows how to use the App Identity API to make a REST call to the Google URL Shortener API. **Note:** the [Google API Client Libraries](https://developers.google.com/discovery/libraries) can also manage much of this for you automatically. \n\n import (\n \t\"context\"\n \t\"net/http\"\n\n \t\"google.golang.org/appengine/urlfetch\"\n\n \t\"golang.org/x/oauth2\"\n \t\"golang.org/x/oauth2/google\"\n \turlshortener \"google.golang.org/api/urlshortener/v1\"\n )\n\n // shortenURL returns a short URL which redirects to the provided url,\n // using Google's urlshortener API.\n func shortenURL(ctx context.Context, url string) (string, error) {\n \ttransport := &oauth2.https://cloud.google.com/appengine/docs/legacy/standard/go111/reference/latest/urlfetch.html#google_golang_org_appengine_urlfetch_Transport{\n \t\tSource: google.AppEngineTokenSource(ctx, urlshortener.UrlshortenerScope),\n \t\tBase: &urlfetch.https://cloud.google.com/appengine/docs/legacy/standard/go111/reference/latest/urlfetch.html#google_golang_org_appengine_urlfetch_Transport{Context: ctx},\n \t}\n \tclient := &http.https://cloud.google.com/appengine/docs/legacy/standard/go111/reference/latest/urlfetch.html#google_golang_org_appengine_urlfetch_Client{Transport: transport}\n\n \tsvc, err := urlshortener.New(client)\n \tif err != nil {\n \t\treturn \"\", err\n \t}\n\n \tresp, err := svc.Url.Insert(&urlshortener.Url{LongUrl: url}).Do()\n \tif err != nil {\n \t\treturn \"\", err\n \t}\n \treturn resp.Id, nil\n }\n\nNote that the application's identity is represented by the service account name, which is typically *applicationid@appspot.gserviceaccount.com* . You can get the exact value by using the `appengine.ServiceAccount` function.\nFor services which offer ACLs, you can grant the application access by granting this account access.\n\nAsserting identity to third-party services\n------------------------------------------\n\nThe token generated by `AccessToken`\nonly works against Google services. However you can use the underlying signing technology to assert the identity of your application to other services. The `appengine.SignBytes` function\nwill sign bytes using a private key unique to your application, and the `appengine.PublicCertificates` function\nwill return certificates which can be used to validate the signature.\n| **Note:** The certificates may be rotated from time to time, and the method may return multiple certificates. Only certificates that are currently valid are returned; if you store signed messages you will need additional key management in order to verify signatures later.\n\nGetting the default Cloud Storage Bucket name\n---------------------------------------------\n\nEach application can have one default Cloud Storage bucket, which\nincludes\n[5GB of free storage and a free quota for I/O operations](/appengine/docs/quotas#Default_Gcs_Bucket).\n\nTo get the name of the default bucket,\n\n\ncall [DefaultBucketName](https://godoc.org/google.golang.org/appengine/file)."]]