From 21a76c1dff9efe890ac17e43b2e8c81e4818d193 Mon Sep 17 00:00:00 2001 From: Loïc Collignon Date: Thu, 9 Nov 2017 15:01:54 +0100 Subject: make it use the nfc-binding. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ia9e032d0a04f2712b7778732314cadee3ffdedbb Signed-off-by: Loïc Collignon --- agl-identity-service/src/agl-forgerock.c | 1 + agl-identity-service/src/agl-identity-binding.c | 56 ++++++++++++++++++++++++- agl-identity-service/src/config.json | 22 ---------- 3 files changed, 55 insertions(+), 24 deletions(-) delete mode 100644 agl-identity-service/src/config.json (limited to 'agl-identity-service/src') diff --git a/agl-identity-service/src/agl-forgerock.c b/agl-identity-service/src/agl-forgerock.c index 9306c7a..2a0d3da 100644 --- a/agl-identity-service/src/agl-forgerock.c +++ b/agl-identity-service/src/agl-forgerock.c @@ -140,6 +140,7 @@ void agl_forgerock_setconfig(struct json_object *conf) confsetstr(conf, "endpoint", &endpoint, endpoint ? : default_endpoint); confsetint(conf, "delay", &expiration_delay, expiration_delay); confsetoidc(conf, "oidc-aia"); + AFB_NOTICE("Forgerock endpoint is: %s", endpoint); } void agl_forgerock_setcb(void (*callback)(struct json_object *data, const char *error)) diff --git a/agl-identity-service/src/agl-identity-binding.c b/agl-identity-service/src/agl-identity-binding.c index afb815d..e850c12 100644 --- a/agl-identity-service/src/agl-identity-binding.c +++ b/agl-identity-service/src/agl-identity-binding.c @@ -50,7 +50,12 @@ static struct json_object *readjson(int fd) buffer = alloca((size_t)(s.st_size)+1); if (read(fd, buffer, (size_t)s.st_size) == (ssize_t)s.st_size) { buffer[s.st_size] = 0; + //AFB_NOTICE("Config file: %s", buffer); result = json_tokener_parse(buffer); + //if (!result) + //{ + // AFB_ERROR("Config file is not a valid JSON: %s", json_tokener_error_desc(json_tokener_get_error(NULL))); + //} } } close(fd); @@ -61,6 +66,7 @@ static struct json_object *readjson(int fd) static struct json_object *get_global_config(const char *name, const char *locale) { int fd = afb_daemon_rootdir_open_locale(name, O_RDONLY, locale); + if (fd < 0) AFB_ERROR("Config file not found: %s", name); return fd < 0 ? NULL : readjson(fd); } @@ -94,7 +100,7 @@ static void setconfig(struct json_object *conf) static void readconfig() { - setconfig(get_global_config("config.json", NULL)); + setconfig(get_global_config("etc/config.json", NULL)); setconfig(get_local_config("/etc/agl/identity-agent-config.json")); setconfig(get_local_config("config.json")); } @@ -187,6 +193,23 @@ static void success (struct afb_req request) afb_req_success(request, NULL, NULL); } +static void on_nfc_subscribed(void *closure, int status, struct json_object *result) +{ + if(!status) + { + } + else AFB_ERROR("Failed to subscribe to nfc events."); +} + +static void on_nfc_started(void *closure, int status, struct json_object *result) +{ + if (!status) + { + afb_service_call("nfc", "subscribe", NULL, on_nfc_subscribed, NULL); + } + else AFB_ERROR("Failed to start nfc polling."); +} + static int service_init() { int rc; @@ -198,9 +221,38 @@ static int service_init() readconfig(); + if (afb_daemon_require_api("nfc", 1)) + return -1; + + afb_service_call("nfc", "start", NULL, on_nfc_started, NULL); + return 0; } +static void on_nfc_target_add(struct json_object *object) +{ + struct json_object * json_uid; + char *uid; + + if (json_object_object_get_ex(object, "UID", &json_uid)) + { + uid = json_object_get_string(json_uid); + AFB_NOTICE("nfc tag detected, call forgerock with vincode=%s and key=%s", vin ? vin : default_vin, uid); + agl_forgerock_download_request(vin ? vin : default_vin, "nfc", uid); + } + else AFB_ERROR("nfc target add event is received but no UID found: %s", json_object_to_json_string(object)); +} + +static void onevent(const char *event, struct json_object *object) +{ + AFB_NOTICE("Received event: %s", event); + if (!strcmp("nfc/on-nfc-target-add", event)) + { + on_nfc_target_add(object); + return; + } + AFB_WARNING("Unhandled event: %s", event); +} // 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 @@ -221,7 +273,7 @@ const struct afb_binding_v2 afbBindingV2 = .verbs = verbs, .preinit = NULL, .init = service_init, - .onevent = NULL, + .onevent = onevent, .noconcurrency = 0 }; diff --git a/agl-identity-service/src/config.json b/agl-identity-service/src/config.json deleted file mode 100644 index 613fc7a..0000000 --- a/agl-identity-service/src/config.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "endpoint": "https://agl-graphapi.forgerocklabs.org/getuserprofilefromtoken", - "vin": "4T1BF1FK5GU260429", - "autoadvise": true, - "delay": 5, - "idp": { - "authorization_endpoint": "", - "token_endpoint": "https://agl-am.forgerocklabs.org:8043/openam/oauth2/stateless/access_token" - }, - "appli": { - "authorization": "Basic c3RhdGVsZXNzOnBhc3N3b3JkMg==", - "username": "bjensen", - "password": "Passw0rd", - "scope": "openid profile email cn sn givenName ou mail postalAddress departmentNumber physicalDeliveryOfficeName facsimileTelephoneNumber" - } -} -/* - "endpoint": "https://frdemo-graphapi.forgerocklabs.org/getuserprofilefromtoken", - "vin": "JTEBU4BF6EK189816", - "delay": 10 -*/ - -- cgit 1.2.3-korg