summaryrefslogtreecommitdiffstats
path: root/agl-identity-service/src/agl-forgerock.c
diff options
context:
space:
mode:
authorLoïc Collignon <loic.collignon@iot.bzh>2017-12-19 17:15:55 +0100
committerLoïc Collignon <loic.collignon@iot.bzh>2017-12-19 17:15:55 +0100
commit4f87bf2d5e0154df8b063948a80d90d614a83252 (patch)
treeaee213912c7972ff8913753264f97b4c0734679c /agl-identity-service/src/agl-forgerock.c
parent4d710564d4ba6ed525ad05fea03310857abd4d63 (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-forgerock.c')
-rw-r--r--agl-identity-service/src/agl-forgerock.c51
1 files changed, 48 insertions, 3 deletions
diff --git a/agl-identity-service/src/agl-forgerock.c b/agl-identity-service/src/agl-forgerock.c
index 2a0d3da..c0c49ab 100644
--- a/agl-identity-service/src/agl-forgerock.c
+++ b/agl-identity-service/src/agl-forgerock.c
@@ -27,6 +27,10 @@
#include "oidc-agent.h"
#include "aia-get.h"
+#ifndef NULL
+#define NULL 0
+#endif
+
static int expiration_delay = 5;
static const char default_endpoint[] = "https://agl-graphapi.forgerocklabs.org/getuserprofilefromtoken";
@@ -83,7 +87,11 @@ static void loaded(struct json_object *data, const char *error)
static void downloaded(void *closure, int status, const void *buffer, size_t size)
{
struct json_object *object, *subobj;
- char *url = closure;
+ struct json_object *objkey = closure;
+ struct json_object *tmp;
+
+ json_object_object_get_ex(objkey, "url", &tmp);
+ const char *url = json_object_get_string(tmp);
/* checks whether discarded */
if (status == 0 && !buffer) {
@@ -127,10 +135,17 @@ static void downloaded(void *closure, int status, const void *buffer, size_t siz
goto end;
}
+ // Save the profile to the database
+ struct json_object* dbr;
+ struct json_object* record = json_object_new_object();
+ json_object_object_add(record, "key", objkey);
+ json_object_object_add(record, "value", json_object_get(subobj));
+ afb_service_call_sync("persistence", "update", record, &dbr);
+
loaded(subobj, NULL);
json_object_put(object);
end:
- free(url);
+ json_object_put(objkey);
}
/** public **************************************************************/
@@ -148,6 +163,21 @@ void agl_forgerock_setcb(void (*callback)(struct json_object *data, const char *
onloaded = callback;
}
+void reply_from_db(void* closure, int status, struct json_object* result)
+{
+ if (status)
+ {
+ AFB_ERROR("Failed to retrieve profile from persistence!");
+ return;
+ }
+
+ struct json_object* tmp;
+ json_object_object_get_ex(result, "response", &tmp);
+ json_object_object_get_ex(tmp, "value", &tmp);
+ AFB_NOTICE("User profile retrieved from persistence: %s", json_object_to_json_string(tmp));
+ loaded(json_object_get(tmp), NULL);
+}
+
void agl_forgerock_download_request(const char *vin, const char *kind, const char *key)
{
int rc;
@@ -155,7 +185,22 @@ void agl_forgerock_download_request(const char *vin, const char *kind, const cha
rc = asprintf(&url, "%s?vin=%s&kind=%s&keytoken=%s", endpoint, vin, kind, key);
if (rc >= 0)
- aia_get(url, expiration_delay, oidc_name, oidc_name, downloaded, url);
+ {
+ struct json_object* obj = json_object_new_object();
+ json_object_object_add(obj, "url", json_object_new_string(url));
+ json_object_object_add(obj, "vin", json_object_new_string(vin));
+ json_object_object_add(obj, "kind", json_object_new_string(kind));
+ json_object_object_add(obj, "key", json_object_new_string(key));
+
+ // Async get from database and from forgerock
+ struct json_object* key = json_object_new_object();
+ json_object_object_add(key, "key", json_object_get(obj));
+ afb_service_call("persistence", "read", key, reply_from_db, NULL);
+
+ // Async get from forgerock
+ aia_get(url, expiration_delay, oidc_name, oidc_name, downloaded, obj);
+ free(url);
+ }
else
AFB_ERROR("out of memory");
}