View Source Boruta.Oauth.Request (Boruta core v2.3.3)
Build an oauth request struct from given input.
Note: Input must have the shape or be a
%Plug.Conn{}
request.
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.
Functions
@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(), prompt: 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
iex>authorize_request(
%{
query_params: %{
"response_type" => "token",
"client_id" => "client_id",
"redirect_uri" => "redirect_uri"
},
},
%User{...}
)
{:ok, %TokenRequest{...}}
@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_authentication: term(), client_id: 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{...}}
@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_authentication: term(), client_id: 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{...}}
@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_authentication: term(), client_id: term(), code: term(), code_verifier: term(), grant_type: term(), redirect_uri: term() } | %Boruta.Oauth.ClientCredentialsRequest{ client_authentication: term(), client_id: term(), grant_type: term(), scope: term() } | %Boruta.Oauth.AuthorizationCodeRequest{ client_authentication: term(), 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_authentication: term(), client_id: 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{...}}