doc.go 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2018 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // Package google provides support for making OAuth2 authorized and authenticated
  5. // HTTP requests to Google APIs. It supports the Web server flow, client-side
  6. // credentials, service accounts, Google Compute Engine service accounts, Google
  7. // App Engine service accounts and workload identity federation from non-Google
  8. // cloud platforms.
  9. //
  10. // A brief overview of the package follows. For more information, please read
  11. // https://developers.google.com/accounts/docs/OAuth2
  12. // and
  13. // https://developers.google.com/accounts/docs/application-default-credentials.
  14. // For more information on using workload identity federation, refer to
  15. // https://cloud.google.com/iam/docs/how-to#using-workload-identity-federation.
  16. //
  17. // OAuth2 Configs
  18. //
  19. // Two functions in this package return golang.org/x/oauth2.Config values from Google credential
  20. // data. Google supports two JSON formats for OAuth2 credentials: one is handled by ConfigFromJSON,
  21. // the other by JWTConfigFromJSON. The returned Config can be used to obtain a TokenSource or
  22. // create an http.Client.
  23. //
  24. // Workload Identity Federation
  25. //
  26. // Using workload identity federation, your application can access Google Cloud
  27. // resources from Amazon Web Services (AWS), Microsoft Azure or any identity
  28. // provider that supports OpenID Connect (OIDC).
  29. // Traditionally, applications running outside Google Cloud have used service
  30. // account keys to access Google Cloud resources. Using identity federation,
  31. // you can allow your workload to impersonate a service account.
  32. // This lets you access Google Cloud resources directly, eliminating the
  33. // maintenance and security burden associated with service account keys.
  34. //
  35. // Follow the detailed instructions on how to configure Workload Identity Federation
  36. // in various platforms:
  37. //
  38. // Amazon Web Services (AWS): https://cloud.google.com/iam/docs/access-resources-aws
  39. // Microsoft Azure: https://cloud.google.com/iam/docs/access-resources-azure
  40. // OIDC identity provider: https://cloud.google.com/iam/docs/access-resources-oidc
  41. //
  42. // For OIDC providers, the library can retrieve OIDC tokens either from a
  43. // local file location (file-sourced credentials) or from a local server
  44. // (URL-sourced credentials).
  45. // For file-sourced credentials, a background process needs to be continuously
  46. // refreshing the file location with a new OIDC token prior to expiration.
  47. // For tokens with one hour lifetimes, the token needs to be updated in the file
  48. // every hour. The token can be stored directly as plain text or in JSON format.
  49. // For URL-sourced credentials, a local server needs to host a GET endpoint to
  50. // return the OIDC token. The response can be in plain text or JSON.
  51. // Additional required request headers can also be specified.
  52. //
  53. //
  54. // Credentials
  55. //
  56. // The Credentials type represents Google credentials, including Application Default
  57. // Credentials.
  58. //
  59. // Use FindDefaultCredentials to obtain Application Default Credentials.
  60. // FindDefaultCredentials looks in some well-known places for a credentials file, and
  61. // will call AppEngineTokenSource or ComputeTokenSource as needed.
  62. //
  63. // Application Default Credentials also support workload identity federation to
  64. // access Google Cloud resources from non-Google Cloud platforms including Amazon
  65. // Web Services (AWS), Microsoft Azure or any identity provider that supports
  66. // OpenID Connect (OIDC). Workload identity federation is recommended for
  67. // non-Google Cloud environments as it avoids the need to download, manage and
  68. // store service account private keys locally.
  69. //
  70. // DefaultClient and DefaultTokenSource are convenience methods. They first call FindDefaultCredentials,
  71. // then use the credentials to construct an http.Client or an oauth2.TokenSource.
  72. //
  73. // Use CredentialsFromJSON to obtain credentials from either of the two JSON formats
  74. // described in OAuth2 Configs, above. The TokenSource in the returned value is the
  75. // same as the one obtained from the oauth2.Config returned from ConfigFromJSON or
  76. // JWTConfigFromJSON, but the Credentials may contain additional information
  77. // that is useful is some circumstances.
  78. package google // import "golang.org/x/oauth2/google"