Skip to content

Latest commit

 

History

History
42 lines (34 loc) · 1.59 KB

README.md

File metadata and controls

42 lines (34 loc) · 1.59 KB

Authorized Client

Build Status Documentation

About

The goal of this library is to make extremely easy to use rest endpoints which are protected by oauth 2.0 client credentials authorization. The client is based on the Reqwest and Oauth2 library

For now this library only supports endpoints which return json bodies.

Usage

Add this library as a dependency to your project.

[dependencies]
authorized_client = { git = "https://github.com/jeroenvervaeke/authorized_client.git" }

Example code

use authorized_client::{AuthorizedClient, Settings};
use url::Url;

// Set up the client
let settings = Settings {
    client_id: "xxxxxxxxxx".to_string(),
    client_secret: "xxxxxxxxxx".to_string(),
    token_url: "https://authorization-server.com/token".to_string(),
    scopes: vec![ "profile".to_string(), "email".to_string() ]
};

// Create a new client, this immediately tries to connect to the auth server and get a bearer token.
// If this fails your settings are probably wrong.
let client = AuthorizedClient::connect(settings).await?;

// Call your desired endpoints
let repsonse: MyResponse = client.get(Url::parse("https://protected-endpoint.com/info")?).await?;