Ory.Connection (ory_client v1.6.2)

Handle Tesla connections for Ory.

Additional middleware can be set in the compile-time or runtime configuration:

config :tesla, Ory.Connection,
  base_url: "https://playground.projects.oryapis.com",
  adapter: Tesla.Adapter.Hackney

The default base URL can also be set as:

config :ory_client,
  :base_url, "https://playground.projects.oryapis.com"

Summary

Types

The list of options that can be passed to new/1.

An arity-1 function or module/function tuple specification which, given a list of scopes, obtains an OAuth2 token.

Functions

Returns the default adapter for this API.

Returns an authentication middleware tuple for a Tesla client that sets the authorization header to the value of the provided bearer token. If the token is provided as a function of arity one, it will be called with a list of requested scopes that will obtain an OAuth2 token.

Returns fully configured middleware for passing to Tesla.client/2.

Configure a client with no authentication.

Configure a client that may have authentication.

Configure a client using bearer authentication with scopes, or with username and password for basic authentication.

Forward requests to Tesla.

Types

@type options() :: [
  base_url: String.t(),
  user_agent: String.t(),
  token: String.t() | token_fetcher(),
  token_scopes: [String.t()],
  username: String.t() | nil,
  password: String.t() | nil
]

The list of options that can be passed to new/1.

  • base_url: Overrides the base URL on a per-client basis.
  • user_agent: Overrides the User-Agent header.
  • token: An OAuth2 token or a token fetcher function.
  • token_scopes: A list of OAuth2 scope strings for use with a token fetcher function.
  • username: A username for basic authentication.
  • password: A password for basic authentication.
Link to this type

token_fetcher()

@type token_fetcher() :: (scopes :: [String.t()] -> String.t()) | {module(), atom()}

An arity-1 function or module/function tuple specification which, given a list of scopes, obtains an OAuth2 token.

Functions

Returns the default adapter for this API.

Link to this function

authorization(token, scopes \\ ["offline", "offline_access", "openid"])

@spec authorization(String.t() | token_fetcher(), [String.t()]) ::
  Tesla.Client.middleware()

Returns an authentication middleware tuple for a Tesla client that sets the authorization header to the value of the provided bearer token. If the token is provided as a function of arity one, it will be called with a list of requested scopes that will obtain an OAuth2 token.

Parameters

  • token: a String or a function of arity one. This value, or the result of the function call, will be set as a bearer token in the authorization header.

  • scopes: an optional list of scopes for use with the token fetcher function. Ignored when token is provided as a String. Defaults to ["offline", "offline_access", "openid"].

Returns

{Tesla.Middleware.Headers, [{"authorization", TOKEN}]}

Link to this function

middleware(options \\ [])

@spec middleware(options()) :: [Tesla.Client.middleware()]

Returns fully configured middleware for passing to Tesla.client/2.

@spec new() :: Tesla.Env.client()

Configure a client with no authentication.

Returns

Tesla.Env.client

@spec new(String.t() | token_fetcher() | options()) :: Tesla.Env.client()

Configure a client that may have authentication.

Parameters

The first parameter may be a token (a string, a token fetcher class, or a module/function tuple) or a keyword list of options. They are documented separately, but only one of them will be passed.

  • token: a String or a function of arity one. This value, or the result of the function call, will be set as a bearer token in the authorization header.
  • options: a keyword list of OpenAPIPetstore.Connection.options.

Returns

Tesla.Env.client

Link to this function

new(token_or_username, scopes_or_password, options \\ [])

@spec new(
  token_or_username :: String.t() | token_fetcher(),
  scopes_or_password :: [String.t()] | String.t(),
  options()
) :: Tesla.Env.client()

Configure a client using bearer authentication with scopes, or with username and password for basic authentication.

Parameters

  • token_or_username: a String representing a bearer token or a username, depending on the type of the next parameter, or a function arity one that returns a bearer token.
  • scopes_or_password: a list of Strings represenging OAuth2 scopes, or a single string that is the password for the username provided.
  • options: a keyword list of OpenAPIPetstore.Connection.options.

Returns

Tesla.Env.client

Link to this function

request(client, options)

@spec request(Tesla.Client.t(), [Tesla.option()]) :: Tesla.Env.result()

Forward requests to Tesla.