예제 #1
0
Promise<RefreshResult> Client::Refresh (
    String access_token,
    String client_token,
    Nullable<Profile> profile
) {

    //	Create JSON request
    JSON::Object obj;
    obj.Add(
        refresh_token_key,
        std::move(access_token),
        refresh_client_token_key,
        std::move(client_token)
    );
    if (!profile.IsNull()) obj.Add(
            refresh_profile_key,
            profile->ToJSON()
        );

    //	Dispatch request
    return dispatch<RefreshResult>(
               refresh_endpoint,
               std::move(obj)
           );

}
예제 #2
0
Promise<AuthenticateResult> Client::Authenticate (
    String username,
    String password,
    Nullable<String> client_token,
    Nullable<Agent> agent
) {

    //	Create JSON request
    JSON::Object obj;
    obj.Add(
        auth_username_key,
        std::move(username),
        auth_password_key,
        std::move(password)
    );
    if (!client_token.IsNull()) obj.Add(
            auth_client_token_key,
            std::move(*client_token)
        );
    if (!agent.IsNull()) obj.Add(
            auth_agent_key,
            agent->ToJSON()
        );

    //	Dispatch request
    return dispatch<AuthenticateResult>(
               auth_endpoint,
               std::move(obj)
           );

}
예제 #3
0
Promise<void> Client::ClientSession (
    String access_token,
    String profile_id,
    String server_id,
    const Vector<Byte> & secret,
    const Vector<Byte> & public_key
) {

    //	Create JSON request
    JSON::Object obj;
    obj.Add(
        session_token_key,
        std::move(access_token),
        session_profile_key,
        std::move(profile_id),
        session_server_id_key,
        get_hash(server_id,secret,public_key)
    );

    //	We have to use a custom URL
    auto request=get_request(std::move(obj));
    request.URL=String::Format(
                    session_url,
                    client_session_endpoint
                );

    //	Dispatch
    return dispatch<void>(std::move(request));

}
예제 #4
0
JSON::Object Profile::ToJSON () {

    JSON::Object retr;
    retr.Add(
        profile_id_key,
        std::move(ID),
        profile_name_key,
        std::move(Name)
    );

    return retr;

}
예제 #5
0
JSON::Object Agent::ToJSON () {

    JSON::Object retr;
    retr.Add(
        agent_name_key,
        std::move(Name),
        agent_version_key,
        to_dbl(Version)
    );

    return retr;

}
예제 #6
0
Promise<void> Client::Invalidate (String access_token, String client_token) {

    //	Create JSON request
    JSON::Object obj;
    obj.Add(
        invalidate_token_key,
        std::move(access_token),
        invalidate_client_token_key,
        std::move(client_token)
    );

    //	Dispatch
    return dispatch<void>(
               invalidate_endpoint,
               std::move(obj)
           );

}
예제 #7
0
Promise<void> Client::Signout (String username, String password) {

    //	Create JSON request
    JSON::Object obj;
    obj.Add(
        signout_username_key,
        std::move(username),
        signout_password_key,
        std::move(password)
    );

    //	Dispatch
    return dispatch<void>(
               signout_endpoint,
               std::move(obj)
           );

}
예제 #8
0
Promise<bool> Client::Validate (String access_token) {

    //	Create JSON request
    JSON::Object obj;
    obj.Add(
        validate_token_key,
        std::move(access_token)
    );

    //	Dispatch request
    return http.Execute(
               get_request(
                   validate_endpoint,
                   std::move(obj)
               )
    ).Then([] (Promise<MCPP::HTTPResponse> p) {

        auto response=p.Get();
        try {

            check(response);

            //	We need to catch the ERROR to see whether
            //	it's JUST RETURNING FALSE ARE YOU KIDDING
            //	ME?
        } catch (const Error & e) {

            if (
                (e.Type==invalid_token_type) &&
                (e.Message==invalid_token_message)
            ) return false;

            throw;

        }

        return true;

    });

}