https://github.com/softprops/gauthz
google api authentication by way of rust :crab:
https://github.com/softprops/gauthz
gcp google
Last synced: 8 months ago
JSON representation
google api authentication by way of rust :crab:
- Host: GitHub
- URL: https://github.com/softprops/gauthz
- Owner: softprops
- Created: 2017-09-06T05:03:38.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-11T04:44:11.000Z (almost 9 years ago)
- Last Synced: 2024-09-10T18:34:35.781Z (almost 2 years ago)
- Topics: gcp, google
- Language: Rust
- Homepage:
- Size: 639 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# gauthz [](https://travis-ci.org/softprops/gauthz) [](https://coveralls.io/github/softprops/gauthz)
> google api service authentication by way of rust
## [Documentation](https://softprops.github.io/gauthz)
## Install
Add the following to your project's `Cargo.toml` file
```toml
[dependencies]
gauthz = "0.1"
```
## Usage
Typical use requires `gauthz::Tokens` configured with a tokio reactor handle
`gauthz::Credentials` and `gauthz::Scope`s representing the access level for
your intended API usage.
> Note your `hyper::Client` _must_ be configured with tls support. Hyper doesn't
provide that out of the box but there are multiple crates that provide the support
A `gauthz::Tokens` instance provides two interfaces `get` which returns a `Future`
that resolves to an access token and a `Stream` which resolves to new tokens when
the current token expires ( typically ) after one hour. The stream interface is
intended for long running applications which will inevitably require access for more
than one hour.
```rust
extern crate futures;
extern crate gauthz;
extern crate tokio_core;
use futures::Future;
use tokio_core::reactor::Core;
use gauthz::{Credentials, Result, Scope, Tokens};
use gauthz::error::ErrorKind;
fn run() -> Result {
let mut core = Core::new()?;
let tokens = Tokens::new(
&core.handle(),
Credentials::default().unwrap(),
vec![Scope::CloudPlatform],
);
core.run(
tokens.get().map(
|t| t.value().to_owned()
)
)
}
fn main() {
match run() {
Ok(ok) => println!("{}", ok),
Err(err) => println!("{}", err),
}
}
```
These tokens may be used in `Authorization` HTTP headers to authenticate with
the Google API's the tokens are scoped to.
## pronounced
> gawthz
Doug Tangren (softprops) 2017