auth.proto 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. // Copyright 2023 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. syntax = "proto3";
  15. package google.api;
  16. option go_package = "google.golang.org/genproto/googleapis/api/serviceconfig;serviceconfig";
  17. option java_multiple_files = true;
  18. option java_outer_classname = "AuthProto";
  19. option java_package = "com.google.api";
  20. option objc_class_prefix = "GAPI";
  21. // `Authentication` defines the authentication configuration for API methods
  22. // provided by an API service.
  23. //
  24. // Example:
  25. //
  26. // name: calendar.googleapis.com
  27. // authentication:
  28. // providers:
  29. // - id: google_calendar_auth
  30. // jwks_uri: https://www.googleapis.com/oauth2/v1/certs
  31. // issuer: https://securetoken.google.com
  32. // rules:
  33. // - selector: "*"
  34. // requirements:
  35. // provider_id: google_calendar_auth
  36. // - selector: google.calendar.Delegate
  37. // oauth:
  38. // canonical_scopes: https://www.googleapis.com/auth/calendar.read
  39. message Authentication {
  40. // A list of authentication rules that apply to individual API methods.
  41. //
  42. // **NOTE:** All service configuration rules follow "last one wins" order.
  43. repeated AuthenticationRule rules = 3;
  44. // Defines a set of authentication providers that a service supports.
  45. repeated AuthProvider providers = 4;
  46. }
  47. // Authentication rules for the service.
  48. //
  49. // By default, if a method has any authentication requirements, every request
  50. // must include a valid credential matching one of the requirements.
  51. // It's an error to include more than one kind of credential in a single
  52. // request.
  53. //
  54. // If a method doesn't have any auth requirements, request credentials will be
  55. // ignored.
  56. message AuthenticationRule {
  57. // Selects the methods to which this rule applies.
  58. //
  59. // Refer to [selector][google.api.DocumentationRule.selector] for syntax
  60. // details.
  61. string selector = 1;
  62. // The requirements for OAuth credentials.
  63. OAuthRequirements oauth = 2;
  64. // If true, the service accepts API keys without any other credential.
  65. // This flag only applies to HTTP and gRPC requests.
  66. bool allow_without_credential = 5;
  67. // Requirements for additional authentication providers.
  68. repeated AuthRequirement requirements = 7;
  69. }
  70. // Specifies a location to extract JWT from an API request.
  71. message JwtLocation {
  72. oneof in {
  73. // Specifies HTTP header name to extract JWT token.
  74. string header = 1;
  75. // Specifies URL query parameter name to extract JWT token.
  76. string query = 2;
  77. // Specifies cookie name to extract JWT token.
  78. string cookie = 4;
  79. }
  80. // The value prefix. The value format is "value_prefix{token}"
  81. // Only applies to "in" header type. Must be empty for "in" query type.
  82. // If not empty, the header value has to match (case sensitive) this prefix.
  83. // If not matched, JWT will not be extracted. If matched, JWT will be
  84. // extracted after the prefix is removed.
  85. //
  86. // For example, for "Authorization: Bearer {JWT}",
  87. // value_prefix="Bearer " with a space at the end.
  88. string value_prefix = 3;
  89. }
  90. // Configuration for an authentication provider, including support for
  91. // [JSON Web Token
  92. // (JWT)](https://tools.ietf.org/html/draft-ietf-oauth-json-web-token-32).
  93. message AuthProvider {
  94. // The unique identifier of the auth provider. It will be referred to by
  95. // `AuthRequirement.provider_id`.
  96. //
  97. // Example: "bookstore_auth".
  98. string id = 1;
  99. // Identifies the principal that issued the JWT. See
  100. // https://tools.ietf.org/html/draft-ietf-oauth-json-web-token-32#section-4.1.1
  101. // Usually a URL or an email address.
  102. //
  103. // Example: https://securetoken.google.com
  104. // Example: 1234567-compute@developer.gserviceaccount.com
  105. string issuer = 2;
  106. // URL of the provider's public key set to validate signature of the JWT. See
  107. // [OpenID
  108. // Discovery](https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata).
  109. // Optional if the key set document:
  110. // - can be retrieved from
  111. // [OpenID
  112. // Discovery](https://openid.net/specs/openid-connect-discovery-1_0.html)
  113. // of the issuer.
  114. // - can be inferred from the email domain of the issuer (e.g. a Google
  115. // service account).
  116. //
  117. // Example: https://www.googleapis.com/oauth2/v1/certs
  118. string jwks_uri = 3;
  119. // The list of JWT
  120. // [audiences](https://tools.ietf.org/html/draft-ietf-oauth-json-web-token-32#section-4.1.3).
  121. // that are allowed to access. A JWT containing any of these audiences will
  122. // be accepted. When this setting is absent, JWTs with audiences:
  123. // - "https://[service.name]/[google.protobuf.Api.name]"
  124. // - "https://[service.name]/"
  125. // will be accepted.
  126. // For example, if no audiences are in the setting, LibraryService API will
  127. // accept JWTs with the following audiences:
  128. // -
  129. // https://library-example.googleapis.com/google.example.library.v1.LibraryService
  130. // - https://library-example.googleapis.com/
  131. //
  132. // Example:
  133. //
  134. // audiences: bookstore_android.apps.googleusercontent.com,
  135. // bookstore_web.apps.googleusercontent.com
  136. string audiences = 4;
  137. // Redirect URL if JWT token is required but not present or is expired.
  138. // Implement authorizationUrl of securityDefinitions in OpenAPI spec.
  139. string authorization_url = 5;
  140. // Defines the locations to extract the JWT. For now it is only used by the
  141. // Cloud Endpoints to store the OpenAPI extension [x-google-jwt-locations]
  142. // (https://cloud.google.com/endpoints/docs/openapi/openapi-extensions#x-google-jwt-locations)
  143. //
  144. // JWT locations can be one of HTTP headers, URL query parameters or
  145. // cookies. The rule is that the first match wins.
  146. //
  147. // If not specified, default to use following 3 locations:
  148. // 1) Authorization: Bearer
  149. // 2) x-goog-iap-jwt-assertion
  150. // 3) access_token query parameter
  151. //
  152. // Default locations can be specified as followings:
  153. // jwt_locations:
  154. // - header: Authorization
  155. // value_prefix: "Bearer "
  156. // - header: x-goog-iap-jwt-assertion
  157. // - query: access_token
  158. repeated JwtLocation jwt_locations = 6;
  159. }
  160. // OAuth scopes are a way to define data and permissions on data. For example,
  161. // there are scopes defined for "Read-only access to Google Calendar" and
  162. // "Access to Cloud Platform". Users can consent to a scope for an application,
  163. // giving it permission to access that data on their behalf.
  164. //
  165. // OAuth scope specifications should be fairly coarse grained; a user will need
  166. // to see and understand the text description of what your scope means.
  167. //
  168. // In most cases: use one or at most two OAuth scopes for an entire family of
  169. // products. If your product has multiple APIs, you should probably be sharing
  170. // the OAuth scope across all of those APIs.
  171. //
  172. // When you need finer grained OAuth consent screens: talk with your product
  173. // management about how developers will use them in practice.
  174. //
  175. // Please note that even though each of the canonical scopes is enough for a
  176. // request to be accepted and passed to the backend, a request can still fail
  177. // due to the backend requiring additional scopes or permissions.
  178. message OAuthRequirements {
  179. // The list of publicly documented OAuth scopes that are allowed access. An
  180. // OAuth token containing any of these scopes will be accepted.
  181. //
  182. // Example:
  183. //
  184. // canonical_scopes: https://www.googleapis.com/auth/calendar,
  185. // https://www.googleapis.com/auth/calendar.read
  186. string canonical_scopes = 1;
  187. }
  188. // User-defined authentication requirements, including support for
  189. // [JSON Web Token
  190. // (JWT)](https://tools.ietf.org/html/draft-ietf-oauth-json-web-token-32).
  191. message AuthRequirement {
  192. // [id][google.api.AuthProvider.id] from authentication provider.
  193. //
  194. // Example:
  195. //
  196. // provider_id: bookstore_auth
  197. string provider_id = 1;
  198. // NOTE: This will be deprecated soon, once AuthProvider.audiences is
  199. // implemented and accepted in all the runtime components.
  200. //
  201. // The list of JWT
  202. // [audiences](https://tools.ietf.org/html/draft-ietf-oauth-json-web-token-32#section-4.1.3).
  203. // that are allowed to access. A JWT containing any of these audiences will
  204. // be accepted. When this setting is absent, only JWTs with audience
  205. // "https://[Service_name][google.api.Service.name]/[API_name][google.protobuf.Api.name]"
  206. // will be accepted. For example, if no audiences are in the setting,
  207. // LibraryService API will only accept JWTs with the following audience
  208. // "https://library-example.googleapis.com/google.example.library.v1.LibraryService".
  209. //
  210. // Example:
  211. //
  212. // audiences: bookstore_android.apps.googleusercontent.com,
  213. // bookstore_web.apps.googleusercontent.com
  214. string audiences = 2;
  215. }