Skip to content

jswanner/req_client_credentials

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ReqClientCredentials

Req plugin for OAuth 2.0 client credentials flow authentication. The access token will be cached and reused for subsequent requests, if the response to the :url returns a 401 response then this plugin will refresh the access token (only refreshes one time). If an :audience is included in :client_credentials_params then this plugin will only run if the schema, host, and port of the :url match that of the :audience.

Usage

req =
  Req.new(
    client_credentials_params: [
      audience: "https://api.example.com/",
      client_id: System.get_env("EXAMPLE_CLIENT_ID"),
      client_secret: System.get_env("EXAMPLE_CLIENT_SECRET")
    ],
    client_credentials_url: "https://auth.example.com/oauth/token",
  )
  |> ReqClientCredentials.attach()
Req.get!(req, url: "https://api.example.com/path")
#=> %Req.Response{}

About

Req plugin for OAuth 2.0 client credential flow authentication

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages