View Source Boruta.Oauth.Request (Boruta core v2.1.5)

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

Link to this function

authorize_request(conn, resource_owner)

View Source
@spec authorize_request(
  conn :: Plug.Conn.t() | %{body_params: map()},
  resource_owner :: struct()
) ::
  {:error,
   %Boruta.Oauth.Error{
     error: :invalid_request,
     error_description: String.t(),
     format: nil,
     redirect_uri: nil,
     state: term(),
     status: :bad_request
   }}
  | {:ok,
     oauth_request ::
       %Boruta.Oauth.CodeRequest{
         client_id: term(),
         code_challenge: term(),
         code_challenge_method: term(),
         grant_type: term(),
         nonce: term(),
         redirect_uri: term(),
         resource_owner: term(),
         response_type: term(),
         response_types: term(),
         scope: term(),
         state: term()
       }
       | %Boruta.Oauth.TokenRequest{
           client_id: term(),
           grant_type: term(),
           nonce: term(),
           prompt: term(),
           redirect_uri: term(),
           resource_owner: term(),
           response_types: term(),
           scope: term(),
           state: term()
         }
       | %Boruta.Oauth.HybridRequest{
           client_id: term(),
           code_challenge: term(),
           code_challenge_method: term(),
           grant_type: term(),
           nonce: term(),
           prompt: term(),
           redirect_uri: term(),
           resource_owner: term(),
           response_mode: term(),
           response_types: term(),
           scope: term(),
           state: term()
         }}

Create request struct from an OAuth authorize request.

Note : resource owner must be provided as current_user assigns.

examples

Examples

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

introspect_request(conn)

View Source
@spec introspect_request(
  conn ::
    Plug.Conn.t() | %{optional(:req_headers) => list(), :body_params => map()}
) ::
  {:error,
   %Boruta.Oauth.Error{
     error: :invalid_request,
     error_description: String.t(),
     format: nil,
     redirect_uri: nil,
     state: term(),
     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

Examples

iex>introspect_request(%{
  body_params: %{
    "token" => "token",
    "client_id" => "client_id",
    "client_secret" => "client_secret",
  }
})
{:ok, %IntrospectRequest{...}}
@spec revoke_request(
  conn ::
    Plug.Conn.t() | %{optional(:req_headers) => list(), :body_params => map()}
) ::
  {:error,
   %Boruta.Oauth.Error{
     error: :invalid_request,
     error_description: String.t(),
     format: nil,
     redirect_uri: nil,
     state: term(),
     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

Examples

iex>revoke_request(%{
  body_params: %{
    "token" => "token",
    "client_id" => "client_id",
    "client_secret" => "client_secret",
  }
})
{:ok, %RevokeRequest{...}}
@spec token_request(
  conn ::
    Plug.Conn.t() | %{optional(:req_headers) => list(), :body_params => map()}
) ::
  {:error,
   %Boruta.Oauth.Error{
     error: :invalid_request,
     error_description: String.t(),
     format: nil,
     redirect_uri: nil,
     state: term(),
     status: :bad_request
   }}
  | {:ok,
     oauth_request ::
       %Boruta.Oauth.AuthorizationCodeRequest{
         client_id: term(),
         code: term(),
         code_verifier: 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(),
           code_verifier: term(),
           grant_type: term(),
           redirect_uri: term()
         }
       | %Boruta.Oauth.TokenRequest{
           client_id: term(),
           grant_type: term(),
           nonce: term(),
           prompt: term(),
           redirect_uri: term(),
           resource_owner: term(),
           response_types: 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

Examples

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