Boruta.Oauth.Request (Boruta core v0.2.1) View Source

Build an oauth request struct from given input.

Note : Input must have the shape or be a %Plug.Conn{} request.

Link to this section Summary

Functions

Create request struct from an OAuth authorize request.

Create request struct from an OAuth introspect request.

Create request struct from an OAuth revoke request.

Create request struct from an OAuth token request.

Link to this section Functions

Specs

authorize_request(conn :: %{body_params: map()}) ::
  {:error,
   %Boruta.Oauth.Error{
     error: :invalid_request,
     error_description: String.t(),
     format: nil,
     redirect_uri: nil,
     status: :bad_request
   }}
  | {:ok,
     oauth_request ::
       %Boruta.Oauth.CodeRequest{
         client_id: term(),
         grant_type: term(),
         redirect_uri: term(),
         resource_owner: term(),
         scope: term(),
         state: term()
       }
       | %Boruta.Oauth.TokenRequest{
           client_id: term(),
           grant_type: term(),
           redirect_uri: term(),
           resource_owner: term(),
           scope: term(),
           state: term()
         }}

Create request struct from an OAuth authorize request.

Note : resource owner must be provided as current_user assigns.

Examples

iex>authorize_request(%{
  query_params: %{
    "response_type" => "token",
    "client_id" => "client_id",
    "redirect_uri" => "redirect_uri"
  },
  assigns: %{current_user: %User{...}}
})
{:ok, %TokenRequest{...}}
Link to this function

introspect_request(conn)

View Source

Specs

introspect_request(
  conn :: %{optional(:req_headers) => list(), :body_params => map()}
) ::
  {:error,
   %Boruta.Oauth.Error{
     error: :invalid_request,
     error_description: String.t(),
     format: nil,
     redirect_uri: nil,
     status: :bad_request
   }}
  | {:ok,
     request :: %Boruta.Oauth.IntrospectRequest{
       client_id: term(),
       client_secret: term(),
       token: term()
     }}

Create request struct from an OAuth introspect request.

Examples

iex>introspect_request(%{
  body_params: %{
    "token" => "token",
    "client_id" => "client_id",
    "client_secret" => "client_secret",
  }
})
{:ok, %IntrospectRequest{...}}

Specs

revoke_request(
  conn :: %{optional(:req_headers) => list(), :body_params => map()}
) ::
  {:error,
   %Boruta.Oauth.Error{
     error: :invalid_request,
     error_description: String.t(),
     format: nil,
     redirect_uri: nil,
     status: :bad_request
   }}
  | {:ok,
     request :: %Boruta.Oauth.RevokeRequest{
       client_id: term(),
       client_secret: term(),
       token: term(),
       token_type_hint: term()
     }}

Create request struct from an OAuth revoke request.

Examples

iex>revoke_request(%{
  body_params: %{
    "token" => "token",
    "client_id" => "client_id",
    "client_secret" => "client_secret",
  }
})
{:ok, %RevokeRequest{...}}

Specs

token_request(
  conn :: %{optional(:req_headers) => list(), :body_params => map()}
) ::
  {:error,
   %Boruta.Oauth.Error{
     error: :invalid_request,
     error_description: String.t(),
     format: nil,
     redirect_uri: nil,
     status: :bad_request
   }}
  | {:ok,
     oauth_request ::
       %Boruta.Oauth.AuthorizationCodeRequest{
         client_id: term(),
         code: term(),
         grant_type: term(),
         redirect_uri: term()
       }
       | %Boruta.Oauth.ClientCredentialsRequest{
           client_id: term(),
           client_secret: term(),
           grant_type: term(),
           scope: term()
         }
       | %Boruta.Oauth.AuthorizationCodeRequest{
           client_id: term(),
           code: term(),
           grant_type: term(),
           redirect_uri: term()
         }
       | %Boruta.Oauth.TokenRequest{
           client_id: term(),
           grant_type: term(),
           redirect_uri: term(),
           resource_owner: term(),
           scope: term(),
           state: term()
         }
       | %Boruta.Oauth.PasswordRequest{
           client_id: term(),
           client_secret: term(),
           grant_type: term(),
           password: term(),
           scope: term(),
           username: term()
         }}

Create request struct from an OAuth token request.

Examples

iex>token_request(%{
  body_params: %{
    "grant_type" => "client_credentials",
    "client_id" => "client_id",
    "client_secret" => "client_secret"
  }
})
{:ok, %ClientCredentialsRequest{...}}