Skip to content

timwis/ex_truelayer_signing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ExTrueLayerSigning

Module for signing and verifying HTTP requests to the TrueLayer API.

Installation

The package can be installed by adding ex_truelayer_signing to your list of dependencies in mix.exs:

def deps do
  [
    {:ex_truelayer_signing, "~> 0.1.0"}
  ]
end

Usage

Via middleware

The easiest way to use this library is via the Tesla middleware it ships with, ExTrueLayerSigning.SigningMiddleware.

defmodule TrueLayer do
  use Tesla

  plug ExTrueLayerSigning.SigningMiddleware
  
  def create_payment(mandate_id, amount) do
    request_body = %{...}
    headers = [{"idempotency-key", UUID.uuid4()}]

    post("/payments", request_body, %{headers: headers})
  end

end

Alternatively, you can sign and verify requests manually

Signing a request

request = %ExTrueLayerSigning.Request{
  method: :post,
  path: "/mandates",
  body: Jason.encode!(%{"foo" => "bar"}),
  headers: [{"Idempotency-Key", "123"}]
}

{:ok, tl_signature} = ExTrueLayerSigning.sign(request)
put_header(request, "tl-signature", tl_signature)

Verify a request signature

signed_request = %ExTrueLayerSigning.Request{
  method: :post,
  path: "/mandates",
  body: Jason.encode!(%{"foo" => "bar"}),
  headers: [
    {"Idempotency-Key", "123"},
    {"tl-signature", "eyJhbGciOiJFUzUxM..."}
  ]
}
:ok = ExTrueLayerSigning.verify(signed_request)

About

Elixir module for signing and verifying HTTP requests to the TrueLayer API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages