Reference documentation and code samples for the googleauth class Google::Auth::ServiceAccountJwtHeaderCredentials.
Authenticates requests using Google's Service Account credentials via
JWT Header.
This class allows authorizing requests for service accounts directly
from credentials from a json key file downloaded from the developer
console (via 'Generate new Json Key'). It is not part of any OAuth2
flow, rather it creates a JWT and sends that as a credential.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# googleauth - Class Google::Auth::ServiceAccountJwtHeaderCredentials (v1.15.0)\n\nVersion latestkeyboard_arrow_down\n\n- [1.15.0 (latest)](/ruby/docs/reference/googleauth/latest/Google-Auth-ServiceAccountJwtHeaderCredentials)\n- [1.14.0](/ruby/docs/reference/googleauth/1.14.0/Google-Auth-ServiceAccountJwtHeaderCredentials)\n- [1.13.1](/ruby/docs/reference/googleauth/1.13.1/Google-Auth-ServiceAccountJwtHeaderCredentials)\n- [1.12.2](/ruby/docs/reference/googleauth/1.12.2/Google-Auth-ServiceAccountJwtHeaderCredentials) \nReference documentation and code samples for the googleauth class Google::Auth::ServiceAccountJwtHeaderCredentials.\n\nAuthenticates requests using Google's Service Account credentials via\nJWT Header.\n\n\nThis class allows authorizing requests for service accounts directly\nfrom credentials from a json key file downloaded from the developer\nconsole (via 'Generate new Json Key'). It is not part of any OAuth2\nflow, rather it creates a JWT and sends that as a credential.\n\n\u003cbr /\u003e\n\ncf [Application Default Credentials](https://cloud.google.com/docs/authentication/production) \n\nInherits\n--------\n\n- Object \n\nExtended By\n-----------\n\n- [Google::Auth::CredentialsLoader](./Google-Auth-CredentialsLoader)\n- [Google::Auth::JsonKeyReader](./Google-Auth-JsonKeyReader)\n\nMethods\n-------\n\n### .make_creds\n\n def self.make_creds(options = {})\n\nCreate a ServiceAccountJwtHeaderCredentials. \n**Parameters**\n\n- **json_key_io** (IO) --- An IO object containing the JSON key\n- **scope** (string\\|array\\|nil) --- the scope(s) to access\n\n### #apply\n\n def apply(a_hash, opts = {})\n\nReturns a clone of a_hash updated with the authorization header\n\n### #apply!\n\n def apply!(a_hash, opts = {})\n\nConstruct a jwt token if the JWT_AUD_URI key is present in the input\nhash.\n\n\n\u003cbr /\u003e\n\nThe jwt token is used as the value of a 'Bearer '.\n\n### #duplicate\n\n def duplicate(options = {})\n\nCreates a duplicate of these credentials \n**Parameter**\n\n- **options** (Hash) ---\n\n Overrides for the credentials parameters.\n The following keys are recognized\n - `private key` the private key in string form\n - `issuer` the SA issuer\n - `scope` the scope(s) to access\n - `project_id` the project id to use during the authentication\n - `quota_project_id` the quota project id to use\n - `universe_domain` the universe domain of the credentials\n\n### #initialize\n\n def initialize(options = {}) -\u003e ServiceAccountJwtHeaderCredentials\n\nInitializes a ServiceAccountJwtHeaderCredentials. \n**Parameter**\n\n- **json_key_io** (IO) --- An IO object containing the JSON key \n**Returns**\n\n- ([ServiceAccountJwtHeaderCredentials](./Google-Auth-ServiceAccountJwtHeaderCredentials)) --- a new instance of ServiceAccountJwtHeaderCredentials\n\n### #logger\n\n def logger()\n\nReturns the value of attribute logger.\n\n### #logger=\n\n def logger=(value)\n\nSets the attribute logger\n\n### #needs_access_token?\n\n def needs_access_token?() -\u003e Boolean\n\nDuck-types the corresponding method from BaseClient \n**Returns**\n\n- (Boolean)\n\n### #new_jwt_token\n\n def new_jwt_token(jwt_aud_uri = nil, options = {})\n\nCreates a jwt uri token.\n\n### #project_id\n\n def project_id()\n\nReturns the value of attribute project_id.\n\n### #quota_project_id\n\n def quota_project_id()\n\nReturns the value of attribute quota_project_id.\n\n### #universe_domain\n\n def universe_domain()\n\nReturns the value of attribute universe_domain.\n\n### #universe_domain=\n\n def universe_domain=(value)\n\nSets the attribute universe_domain\n\n### #updater_proc\n\n def updater_proc()\n\nReturns a reference to the #apply method, suitable for passing as\na closure\n\nConstants\n---------\n\n### JWT_AUD_URI_KEY\n\n**value:**:jwt_aud_uri\n\n### AUTH_METADATA_KEY\n\n**value:**Google::Auth::BaseClient::AUTH_METADATA_KEY\n\n### TOKEN_CRED_URI\n\n**value:** \"\u003chttps://www.googleapis.com/oauth2/v4/token\".freeze\u003e\n\n### SIGNING_ALGORITHM\n\n**value:**\"RS256\".freeze\n\n### EXPIRY\n\n**value:**60"]]