diff options
author | Loïc Collignon <loic.collignon@iot.bzh> | 2017-12-19 17:15:55 +0100 |
---|---|---|
committer | Loïc Collignon <loic.collignon@iot.bzh> | 2017-12-19 17:15:55 +0100 |
commit | 4f87bf2d5e0154df8b063948a80d90d614a83252 (patch) | |
tree | aee213912c7972ff8913753264f97b4c0734679c /agl-identity-service/src/agl-identity-binding.c | |
parent | 4d710564d4ba6ed525ad05fea03310857abd4d63 (diff) |
added a fake auth verb for testing purpose and use persistence api to store user profile.
Change-Id: Ifc38f01664dec91150ca7574e4263ee0bc755653
Signed-off-by: Loïc Collignon <loic.collignon@iot.bzh>
Diffstat (limited to 'agl-identity-service/src/agl-identity-binding.c')
-rw-r--r-- | agl-identity-service/src/agl-identity-binding.c | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/agl-identity-service/src/agl-identity-binding.c b/agl-identity-service/src/agl-identity-binding.c index b10703e..12f43bd 100644 --- a/agl-identity-service/src/agl-identity-binding.c +++ b/agl-identity-service/src/agl-identity-binding.c @@ -29,6 +29,10 @@ #include "agl-forgerock.h" +#ifndef NULL +#define NULL 0 +#endif + static struct afb_event event; static struct json_object *current_identity; @@ -126,6 +130,18 @@ static int send_event_object(const char *name, const char *id, const char *nick) static void do_login(struct json_object *desc) { + if (current_identity == NULL && desc == NULL) return; // Switching from NULL to NULL -> do nothing + if (current_identity && desc) + { + const char* a = json_object_to_json_string(current_identity); + const char* b = json_object_to_json_string(desc); + if (strcmp(a, b) == 0) + { + AFB_NOTICE("Reloging of the same user."); + return; // Switching from one user to the same user -> do nothing + } + } + struct json_object *object; /* switching the user */ @@ -226,6 +242,9 @@ static int service_init() if (afb_daemon_require_api("nfc", 1)) return -1; + if (afb_daemon_require_api("persistence", 1)) + return -1; + afb_service_call("nfc", "start", NULL, on_nfc_started, NULL); return 0; @@ -257,6 +276,35 @@ static void onevent(const char *event, struct json_object *object) AFB_WARNING("Unhandled event: %s", event); } +static void fake_auth(struct afb_req req) +{ + struct json_object* req_object; + struct json_object* kind_object; + struct json_object* key_object; + + req_object = afb_req_json(req); + + if (!json_object_object_get_ex(req_object, "kind", &kind_object)) + { + afb_req_fail(req, "Missing arg: kind", NULL); + return; + } + + if (!json_object_object_get_ex(req_object, "key", &key_object)) + { + afb_req_fail(req, "Missing arg: key", NULL); + return; + } + + const char* kind = json_object_get_string(kind_object); + const char* key = json_object_get_string(key_object); + + send_event_object("incoming", key, key); + agl_forgerock_download_request(vin ? vin : default_vin, kind, key); + + afb_req_success(req, NULL, "fake auth success!"); +} + // NOTE: this sample does not use session to keep test a basic as possible // in real application most APIs should be protected with AFB_SESSION_CHECK static const struct afb_verb_v2 verbs[]= @@ -266,6 +314,7 @@ static const struct afb_verb_v2 verbs[]= {"fake-login" , fake_login , NULL, "fake a login" , AFB_SESSION_NONE }, {"logout" , logout , NULL, "log the current user out", AFB_SESSION_NONE }, {"get" , get , NULL, "get data" , AFB_SESSION_NONE }, + {"fake-auth" , fake_auth , NULL, "fake an authentication" , AFB_SESSION_NONE }, {NULL} }; @@ -282,4 +331,3 @@ const struct afb_binding_v2 afbBindingV2 = }; /* vim: set colorcolumn=80: */ - |