doc.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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,
  7. // Google App Engine service accounts and workload identity federation
  8. // from non-Google 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 and SAML providers, the library can retrieve tokens in three ways:
  43. // from a local file location (file-sourced credentials), from a server
  44. // (URL-sourced credentials), or from a local executable (executable-sourced
  45. // credentials).
  46. // For file-sourced credentials, a background process needs to be continuously
  47. // refreshing the file location with a new OIDC token prior to expiration.
  48. // For tokens with one hour lifetimes, the token needs to be updated in the file
  49. // every hour. The token can be stored directly as plain text or in JSON format.
  50. // For URL-sourced credentials, a local server needs to host a GET endpoint to
  51. // return the OIDC token. The response can be in plain text or JSON.
  52. // Additional required request headers can also be specified.
  53. // For executable-sourced credentials, an application needs to be available to
  54. // output the OIDC token and other information in a JSON format.
  55. // For more information on how these work (and how to implement
  56. // executable-sourced credentials), please check out:
  57. // https://cloud.google.com/iam/docs/using-workload-identity-federation#oidc
  58. //
  59. // # Credentials
  60. //
  61. // The Credentials type represents Google credentials, including Application Default
  62. // Credentials.
  63. //
  64. // Use FindDefaultCredentials to obtain Application Default Credentials.
  65. // FindDefaultCredentials looks in some well-known places for a credentials file, and
  66. // will call AppEngineTokenSource or ComputeTokenSource as needed.
  67. //
  68. // Application Default Credentials also support workload identity federation to
  69. // access Google Cloud resources from non-Google Cloud platforms including Amazon
  70. // Web Services (AWS), Microsoft Azure or any identity provider that supports
  71. // OpenID Connect (OIDC). Workload identity federation is recommended for
  72. // non-Google Cloud environments as it avoids the need to download, manage and
  73. // store service account private keys locally.
  74. //
  75. // DefaultClient and DefaultTokenSource are convenience methods. They first call FindDefaultCredentials,
  76. // then use the credentials to construct an http.Client or an oauth2.TokenSource.
  77. //
  78. // Use CredentialsFromJSON to obtain credentials from either of the two JSON formats
  79. // described in OAuth2 Configs, above. The TokenSource in the returned value is the
  80. // same as the one obtained from the oauth2.Config returned from ConfigFromJSON or
  81. // JWTConfigFromJSON, but the Credentials may contain additional information
  82. // that is useful is some circumstances.
  83. package google // import "golang.org/x/oauth2/google"