D2lvalenceElixir.Auth.D2LUserContext (D2lvalenceElixir v0.1.0) View Source
Link to this section Summary
Functions
Create a properly tokenized URL for a new request through this user context.
Create a properly tokenized URL for a new request through this user context, starting from a full URL.
Creates a Full User Context from the app context and the simple authentication information created by get_simple_authentication_keys/1
Takes a full D2LUserContext and returns a map with only the basic information for authentication. This is usefull for Phoenix session storage. You don't send app_id and app_key to the user.
Interpret the result made for an API call through this user context.
Constructs a new authenticated calling user context.
Adjust the known time skew between the local client using this user context, and the back-end service. :param newSkewMillis: New server time-skew value, in milliseconds.
Link to this section Functions
Specs
create_authenticated_url(
%D2lvalenceElixir.Auth.D2LUserContext{
anonymous: term(),
app_id: term(),
app_key: term(),
encrypt_requests: term(),
host: term(),
scheme: term(),
server_skew: term(),
user_id: term(),
user_key: term()
},
%{method: String.t()}
| %{api_route: String.t()}
| %{method: String.t(), api_route: String.t()}
| []
) :: String.t()
Create a properly tokenized URL for a new request through this user context.
:param api_route: API route to invoke on the back-end service (get all versions route by default). :param method: Method for the request (GET by default, POST, etc).
:returns: URI string you can fashion into an HTTP request, containing the time-limited authentication token parameters needed for a Valence API call.
decorate_url_with_authentication(user_context, url, options \\ [])
View SourceSpecs
decorate_url_with_authentication(
%D2lvalenceElixir.Auth.D2LUserContext{
anonymous: term(),
app_id: term(),
app_key: term(),
encrypt_requests: term(),
host: term(),
scheme: term(),
server_skew: term(),
user_id: term(),
user_key: term()
},
String.t(),
%{method: String.t()} | []
) :: String.t()
Create a properly tokenized URL for a new request through this user context, starting from a full URL.
:param url: Full URL to call on the back-end service; no default value. param method: Method for the request (GET by default, POST, etc).
:returns: URL you can use for an HTTP request, containing the time-limited authentication token parameters needed for a Valence API call.
Specs
get_full_user_context(
%D2lvalenceElixir.Auth.D2LAppContext{app_id: String.t(), app_key: String.t()},
%D2lvalenceElixir.Auth.D2LUserContextSimple{
anonymous: boolean(),
encrypt_requests: boolean(),
host: String.t(),
scheme: String.t(),
server_skew: integer(),
user_id: String.t(),
user_key: String.t()
}
) ::
{:error, String.t()}
| {:ok,
%D2lvalenceElixir.Auth.D2LUserContext{
anonymous: boolean(),
app_id: String.t(),
app_key: String.t(),
encrypt_requests: boolean(),
host: String.t(),
scheme: String.t(),
server_skew: integer(),
user_id: String.t(),
user_key: String.t()
}}
Creates a Full User Context from the app context and the simple authentication information created by get_simple_authentication_keys/1
Specs
get_simple_user_context(%D2lvalenceElixir.Auth.D2LUserContext{
anonymous: term(),
app_id: term(),
app_key: term(),
encrypt_requests: term(),
host: term(),
scheme: term(),
server_skew: term(),
user_id: String.t(),
user_key: String.t()
}) :: %{user_id: String.t(), user_key: String.t()}
Takes a full D2LUserContext and returns a map with only the basic information for authentication. This is usefull for Phoenix session storage. You don't send app_id and app_key to the user.
Specs
interpret_result(
%D2lvalenceElixir.Auth.D2LUserContext{
anonymous: term(),
app_id: term(),
app_key: term(),
encrypt_requests: term(),
host: term(),
scheme: term(),
server_skew: term(),
user_id: term(),
user_key: term()
},
integer(),
String.t(),
String.t() | nil
) :: :invalid_sig | :no_permission | :okay | :unknown
Interpret the result made for an API call through this user context.
:param result_code: The HTTP result code from the response; if a successful result (2xx), this method ignores the response. :param response: Response passed back by the back-end service. The precise form of this is implementation dependent. It could be a string, or a file object, or a Response object of some kind. :param logfile: Optional. A caller might want to provide a file stream for logging purposes; if present, this method should write logging messages to this file stream.
:returns: One of the enumerated D2LAuthResult class variables.
Specs
new(%{
host: String.t(),
user_id: String.t(),
user_key: String.t(),
app_id: String.t(),
app_key: String.t(),
encrypt_requests: true | false,
server_skew: integer()
}) ::
{:error, String.t()}
| {:ok,
%D2lvalenceElixir.Auth.D2LUserContext{
anonymous: false | true,
app_id: String.t(),
app_key: String.t(),
encrypt_requests: boolean(),
host: String.t(),
scheme: String.t(),
server_skew: integer(),
user_id: String.t(),
user_key: String.t()
}}
Constructs a new authenticated calling user context.
Clients are not intended to invoke this constructor directly; rather
they should use the D2LAppContext.create_user_context() factory
method, or the fashion_user_context() factory function.
:param hostName: Host/port string for the back-end service. :param user_id: User ID provided by the back-end service to the
authenticated client application.:param user_key: User Key provided by the back-end service to the
authenticated client application.:param encrypt_requests: If true, use HTTPS for requests made through
this user context; if false (the default), use
HTTP.:param server_skew: Time skew between the service's time and the client
application's time, in milliseconds.:param signer: A signer instance that implements D2LSigner.
:return error:: If you provide None for hostName, port, user_id,
or user_key parameters.
Specs
set_new_skew(
%D2lvalenceElixir.Auth.D2LUserContext{
anonymous: term(),
app_id: term(),
app_key: term(),
encrypt_requests: term(),
host: term(),
scheme: term(),
server_skew: term(),
user_id: term(),
user_key: term()
},
integer()
) :: %D2lvalenceElixir.Auth.D2LUserContext{
anonymous: term(),
app_id: term(),
app_key: term(),
encrypt_requests: term(),
host: term(),
scheme: term(),
server_skew: term(),
user_id: term(),
user_key: term()
}
Adjust the known time skew between the local client using this user context, and the back-end service. :param newSkewMillis: New server time-skew value, in milliseconds.