Skip to content

Generate authentication tokens for google api requests

Notifications You must be signed in to change notification settings

kronos-et-al/google-jwt-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

google-jwt-auth

Generate authentication tokens for Google api requests.

See Using OAuth 2.0 for Server to Server Applications for a description of the procedure.

Setup

To obtain a token, some tasks need to be done:

  • Access to the Google console.
  • Access to (create) a Google service account.
  • Rights to create a key for that service account.
  • Access to the json key file (can be downloaded during the service account key generation).
  • Select the needed api usage from this Website. More than one usage can be used by seperating them with commas. An empty usage results in an error.

This json file is important and necessary to use this crate. See in Examples/Usage its usage.

Each token request has a lifetime. This lifetime need to be provided as param in seconds. Allowed are values between 30 to 3600.

Current Version: 0.1.1 (BETA)

Current State: Stable!

To be done

The next updates take care of the following:

  • Improved error messages
  • Detect error returns
  • Usage Enum Types
  • Token-Buffer (for now: every token generation results in a rest request)

Example / Usage

...
let config = AuthConfig::build(                                     //<-- Config can be reused
    fs::read_to_string("service_account.json").unwrap(),            //<-- JSON as string
    &Usage::CloudVision,                                            //<-- Api-Usage
).unwrap(); 
let token = config.generate_auth_token(3600).await.unwrap();        //<-- Generate token
println!("{}", token);
...

Errors

This chapter should help to determine who/which causes the problem and how to fix it:

LibError Type Solution (not guaranteed)
AuthenticationError invalid_grant Your service-client.json is no longer valid as the key got deleted in the google console. Replace this file with a new one by generating a new key.

This table is WIP and will change if new errors occur or someone requests a related issue.

About

Generate authentication tokens for google api requests

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages