Module watts_http_api

This module implements the validation of a request and once it is valid execute the corresponding action, which is always calling the main interface to actions on the WaTTS system.

See also: watts.

Description

This module implements the validation of a request and once it is valid execute the corresponding action, which is always calling the main interface to actions on the WaTTS system.

Data Types

request_type()

request_type() = oidcp | info | logout | service | credential | access_token | cred_data | undefined

state()

state() = #state{}

Function Index

allow_missing_post/2it is not allowed to post to urls that do not exist.
allowed_methods/2return the allowed methods.
content_types_accepted/2return the accepted content types (only json).
content_types_provided/2return the provided content types (only json).
delete_resource/2perform a deletion of a resource.
extract_info/1*extrac information from the request and put them into the state.
get_json/2handle the get requests.
get_return_urls/1*get the return urls of an rsp, if valid.
handle_queue_result/2*handle the result of a queue request.
init/3upgrade to cowboy rest.
is_authorized/2check if the user is authorized to perform the request.
is_bad_version/2*return if the given version is bad.
is_malformed/1*check if the state is a malformed request.
is_malformed/6*check if the request is malformed.
keep_session_alive/2*decide if the session should be closed or not.
malformed_request/2return if a request is malformed.
perform_cookie_logout/2*logout by deleteing the cookie.
perform_get/4*handle the get requests.
perform_logout/3*perform a logout, either by cookie or by just closing the session.
perform_post/6*perform a post, meaning a translation.
post_json/2handle the post requests.
request_queue_if_configured/2*stand in the queue and request a token, if configured.
resource_exists/2return if a resource exists.
rest_init/2intialize the rest request by creating a state with all preparsed infos.
rest_terminate/2terminate the rest request, this ensures the token is given back.
return_json_credential/2*return a single temp_credential (includes oidc_login) as json.
return_json_credential_list/2*return the credential list in json format.
return_json_info/1*create and return the info data.
return_json_oidc_list/1*return the list of supported OpenID Connect provider.
return_json_service_list/2*return the list of the services limited to the given keys.
return_rsp_if_enabled/3*return the given rsp, if it is enabled.
safe_binary_to_integer/1*safe conversion of binary to integer.
service_available/2check if the service is available (still within the rate limit) cred_data is not checked, they always pass.
temp_cred_id_to_url/3*convert a temp cred Id to its url.
temp_cred_id_to_url/4*create the url depending on the version of the api used.
update_cookie_or_end_session/2*decide to update the cookie for the session or logout.
update_cookie_or_end_session/4*either update the cookie for the session or logout.
verify_body/1*verify the passed body, try to parse the json.
verify_content_type/1*verify the content is json or undefined.
verify_id/1*verify the id.
verify_issuer/1*verify the issuer.
verify_method/1*verify the method.
verify_session/1*verify the session, just check if it is a pid.
verify_token/1*verify the token passed.
verify_type/1*verify the request type.
verify_version/1*verify the passed version.

Function Details

allow_missing_post/2

allow_missing_post(Req::cowboy_req:req(), State::state()) -> {false, cowboy_req:req(), state()}

it is not allowed to post to urls that do not exist

allowed_methods/2

allowed_methods(Req::cowboy_req:req(), State::state()) -> {[binary()], cowboy_req:req(), state()}

return the allowed methods

content_types_accepted/2

content_types_accepted(Req::cowboy_req:req(), State::state()) -> {[tuple()], cowboy_req:req(), state()}

return the accepted content types (only json)

content_types_provided/2

content_types_provided(Req::cowboy_req:req(), State::state()) -> {[tuple()], cowboy_req:req(), state()}

return the provided content types (only json)

delete_resource/2

delete_resource(Req::cowboy_req:req(), State::state()) -> {boolean(), cowboy_req:req(), state()}

perform a deletion of a resource. this is revoking a credential

extract_info/1 *

extract_info(Req::cowboy_req:req()) -> {state(), cowboy_req:req()}

extrac information from the request and put them into the state

get_json/2

get_json(Req::cowboy_req:req(), State::state()) -> {binary(), cowboy_req:req(), state()}

handle the get requests

get_return_urls/1 *

get_return_urls(Rsp::undefined | binary()) -> {undefined, undefined} | {binary(), binary()}

get the return urls of an rsp, if valid

handle_queue_result/2 *

handle_queue_result(X1::{ok, any()} | any(), State::state()) -> {boolean(), state()}

handle the result of a queue request

init/3

init(X1::any(), Req::any(), Opts::any()) -> {upgrade, protocol, cowboy_rest}

upgrade to cowboy rest

is_authorized/2

is_authorized(Req::cowboy_req:req(), State::state()) -> {boolean(), cowboy_req:req(), state()}

check if the user is authorized to perform the request

is_bad_version/2 *

is_bad_version(Version::integer() | any(), HeaderUsed::boolean()) -> boolean()

return if the given version is bad

is_malformed/1 *

is_malformed(State::state()) -> {boolean(), state()}

check if the state is a malformed request

is_malformed/6 *

is_malformed(Method, ContentType, Type, Id, Issuer, Body) -> boolean()

check if the request is malformed

keep_session_alive/2 *

keep_session_alive(X1::watts_session:type(), X2::atom()) -> boolean()

decide if the session should be closed or not

malformed_request/2

malformed_request(Req::cowboy_req:req(), State::state()) -> {boolean(), cowboy_req:req(), state()}

return if a request is malformed

perform_cookie_logout/2 *

perform_cookie_logout(Session::pid(), Req::cowboy_req:req()) -> {ok, cowboy_req:req()}

logout by deleteing the cookie

perform_get/4 *

perform_get(RequestType, Id, Session, Version) -> binary()

handle the get requests. This includes:

perform_logout/3 *

perform_logout(Session::pid(), X2::watts_session:type(), Req::cowboy_req:req()) -> {ok, cowboy_req:req()}

perform a logout, either by cookie or by just closing the session

perform_post/6 *

perform_post(Req::cowboy_req:req(), X2::credential, X3::undefined, Data::watts_service:info(), Session::pid(), Ver::integer()) -> {cowboy_req:req(), {true, binary()} | false}

perform a post, meaning a translation

post_json/2

post_json(Req::cowboy_req:req(), State::state()) -> {{true, binary()} | false, cowboy_req:req(), state()}

handle the post requests

request_queue_if_configured/2 *

request_queue_if_configured(X1::boolean(), State::state()) -> {boolean(), state()}

stand in the queue and request a token, if configured

resource_exists/2

resource_exists(Req::cowboy_req:req(), State::state()) -> {boolean(), cowboy_req:req(), state()}

return if a resource exists

rest_init/2

rest_init(Req0::cowboy_req:req(), Opts::any()) -> {ok, cowboy_req:req(), state()}

intialize the rest request by creating a state with all preparsed infos

rest_terminate/2

rest_terminate(Req::cowboy_req:req(), State::state()) -> ok

terminate the rest request, this ensures the token is given back

return_json_credential/2 *

return_json_credential(Cred::watts:temp_cred(), X2::integer()) -> binary()

return a single temp_credential (includes oidc_login) as json

To do

return_json_credential_list/2 *

return_json_credential_list(Credentials::[map()], Version::integer()) -> binary()

return the credential list in json format

return_json_info/1 *

return_json_info(Session::pid()) -> binary()

create and return the info data

return_json_oidc_list/1 *

return_json_oidc_list(Oidc::[map()]) -> binary()

return the list of supported OpenID Connect provider

return_json_service_list/2 *

return_json_service_list(Services::[map()], Keys::[atom()]) -> binary()

return the list of the services limited to the given keys

return_rsp_if_enabled/3 *

return_rsp_if_enabled(Rsp::binary(), X2::boolean(), X3::boolean()) -> binary() | unknown_rsp | rsps_disabled

return the given rsp, if it is enabled

safe_binary_to_integer/1 *

safe_binary_to_integer(Version::binary()) -> integer()

safe conversion of binary to integer

service_available/2

service_available(Req::cowboy_req:req(), State::state()) -> {boolean(), cowboy_req:req(), state()}

check if the service is available (still within the rate limit) cred_data is not checked, they always pass

temp_cred_id_to_url/3 *

temp_cred_id_to_url(Id::binary(), IssuerId::binary(), Version::pos_integer()) -> binary()

convert a temp cred Id to its url

temp_cred_id_to_url/4 *

temp_cred_id_to_url(ApiBase::binary(), Id::binary(), IssuerId::binary(), ApiVersion::pos_integer()) -> binary()

create the url depending on the version of the api used

update_cookie_or_end_session/2 *

update_cookie_or_end_session(Req::cowboy_req:req(), State::state()) -> {ok, cowboy_req:req()}

decide to update the cookie for the session or logout

update_cookie_or_end_session/4 *

update_cookie_or_end_session(X1::boolean(), Session::pid(), SessType::watts_session:type(), Req::cowboy_req:req()) -> {ok, cowboy_req:req()}

either update the cookie for the session or logout

verify_body/1 *

verify_body(Data::binary()) -> undefined | map()

verify the passed body, try to parse the json

verify_content_type/1 *

verify_content_type(X1::tuple()) -> json | undefined | unsupported

verify the content is json or undefined

verify_id/1 *

verify_id(Id::binary() | undefined) -> binary() | undefined

verify the id

verify_issuer/1 *

verify_issuer(Rsp::binary() | undefined) -> binary() | undefined | rsps_disabled | unkonwn_rsp | bad_issuer

verify the issuer

verify_method/1 *

verify_method(X1::binary()) -> get | post | delete

verify the method

verify_session/1 *

verify_session(X1::{ok, pid()} | any()) -> pid() | undefined

verify the session, just check if it is a pid

verify_token/1 *

verify_token(Token::binary() | undefined) -> binary() | undefined | bad_token

verify the token passed

verify_type/1 *

verify_type(Type::binary() | undefined) -> request_type()

verify the request type

verify_version/1 *

verify_version(X1::binary() | undefined) -> integer()

verify the passed version


Generated by EDoc