# Solid-ldflex authenticated requests

**URL:** <https://forum.solidproject.org/t/solid-ldflex-authenticated-requests/4270>\
**Category:** Solid App Development FAQs\
**Created:** [May 2, 2021, 11:54pm UTC](https://forum.solidproject.org/t/solid-ldflex-authenticated-requests/4270 "2021-05-02T23:54:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramonvilafer](https://avatars.discourse-cdn.com/v4/letter/r/e99b99/32.png) [@ramonvilafer](https://forum.solidproject.org/u/ramonvilafer)\
**Post date:** [May 2, 2021, 11:54pm UTC](https://forum.solidproject.org/t/solid-ldflex-authenticated-requests/4270/1 "2021-05-02T23:54:06Z")

</div>

Hello everyone!

First of all: I have recently started reading about solid, linked data and so on (I am an undergrad student in Software Engineering) so please, excuse me if I say something incorrect!.

I’m currently developing an Android App which uses Solid to retrieve and store user’s friends (aka: foaf:knows).

The application doesn’t communicate itself with the pod by any means, instead, it uses a REST API (built with nodejs, express and solid-ldflex to fetch the user’s friends from his pod).

The point is that I am able to log the user in his pod (with solid-auth-cli) and fetch its friends (I know this is public data so authentication is not really needed here) but I am absolutely lost about how to add a friend using solid-ldflex, something that, I know its posible as stated here: [SOCOM Tutorial Slides - LDflex](https://comunica.github.io/Tutorial-ISWC2019-Slides-LDflex/#write-support)

`await [https://julianrojas.solid.org/profile/#me].add('foaf:givenName' , 'Julian')`

These slides show a way to modify the user’s given name (which I guess is an authenticated operation) but don’t really provide any insight about the authentication part.

In the worst case scenario (that is, I can’t use solid-ldflex) I won’t really have a problem using basic SPARQL queries (but again, I don’t know how to run authenticated operations) :

`INSERT DATA { <user_webid> <http://xmlns.com/foaf/0.1/knows> <friend_webid> . } `

TL;DR:

I need a way to combine solid-ldflex and solid-auth-cli to add a friend to an authenticated user’s pod in a server side enviroment running nodejs.

Thanks for reading me!

---

<div class="post-metadata">

**Author:** ![Vincent](https://avatars.discourse-cdn.com/v4/letter/v/e9bcb4/32.png) [@Vincent](https://forum.solidproject.org/u/Vincent)\
**Post date:** [May 3, 2021, 8:15am UTC](https://forum.solidproject.org/t/solid-ldflex-authenticated-requests/4270/2 "2021-05-03T08:15:51Z")

</div>

Hi Ramón, welcome to the Solid forum! Unfortunately I think solid-ldflex automatically uses solid-auth-client, so I don’t think it will work with solid-auth-cli (but maybe @jeffz, the author of solid-auth-cli, can confirm). That said, [the README of solid-auth-cli](https://github.com/jeff-zucker/solid-auth-cli) mentions that it’s been deprecated and replaced by [solid-node-client](https://github.com/solid/solid-node-client), which I presume it’s good to be aware of.

Also note that basic SPARQL queries aren’t your only alternative to solid-ldflex. For example, I work on Inrupt’s solid-client library, which is [more extensively documented](https://docs.inrupt.com/developer-tools/javascript/client-libraries/) and also supports Node.js. Inrupt also has [solid-client-authn-node](https://docs.inrupt.com/developer-tools/javascript/client-libraries/tutorial/authenticate/#in-a-node-js-environment), which allows you to authenticate a user and then provides a `fetch` function that can make authenticated requests, in case you really just want to run raw SPARQL queries. (And I think Jeff’s solid-node-client supports this too?)

---

<div class="post-metadata">

**Author:** ![ramonvilafer](https://avatars.discourse-cdn.com/v4/letter/r/e99b99/32.png) [@ramonvilafer](https://forum.solidproject.org/u/ramonvilafer)\
**Post date:** [May 3, 2021, 9:04am UTC](https://forum.solidproject.org/t/solid-ldflex-authenticated-requests/4270/3 "2021-05-03T09:04:48Z")

</div>

Thanks @Vincent, I am aware that solid-auth-cli has been deprecated, I use it because I found its documentation to be more straighforward (and because my app is just a prototype I don’t think there is any risk).  
I guess its a good moment to migrate to solid-client-authn-node! Could you provide and example of raw SPARQL with the `fetch()` function? (I couldn’t find anything in the documentation).

---

<div class="post-metadata">

**Author:** ![Vincent](https://avatars.discourse-cdn.com/v4/letter/v/e9bcb4/32.png) [@Vincent](https://forum.solidproject.org/u/Vincent)\
**Post date:** [May 3, 2021, 9:43am UTC](https://forum.solidproject.org/t/solid-ldflex-authenticated-requests/4270/4 "2021-05-03T09:43:41Z")

</div>

Off the top of my head, it’d be something like:

```auto
session.fetch("https://your.pod/resource", {
    method: "PATCH",
    headers: {
        "Content-Type": "application/sparql-update",
    },
    body: "INSERT DATA { <user_webid> <http://xmlns.com/foaf/0.1/knows> <friend_webid> . }",
});

```

(But I’m not super familiar with SPARQL so might need some tweaking.)

Best place for more information about that is just [the Solid spec](https://solidproject.org/TR/) I think, as this is exactly what libraries try not to expose you to 🙂

---

<div class="post-metadata">

**Author:** ![jeffz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/jeffz/32/600_2.png) [@jeffz](https://forum.solidproject.org/u/jeffz)\
**Post date:** [May 3, 2021, 4:43pm UTC](https://forum.solidproject.org/t/solid-ldflex-authenticated-requests/4270/5 "2021-05-03T16:43:47Z")

</div>

At the moment, solid-auth-cli should work on NSS servers so if you are only working on POC, it should be fine. Both it and solid-node-client support SPARQL patch but you must pass in a $rdf parser object.

---

<div class="post-metadata">

**Author:** ![Smag0](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/smag0/32/310_2.png) [@Smag0](https://forum.solidproject.org/u/Smag0)\
**Post date:** [May 5, 2021, 7:01pm UTC](https://forum.solidproject.org/t/solid-ldflex-authenticated-requests/4270/6 "2021-05-05T19:01:46Z")

</div>

> [@ramonvilafer](#):
>
> The application doesn’t communicate itself with the pod by any means, instead, it uses a REST API (built with nodejs, express and solid-ldflex to fetch the user’s friends from his pod).

Could’nt you use webapps facilities and develop your app in js ? It works really great on Android

---

<div class="post-metadata">

**Author:** ![wenjingli-qa](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/wenjingli-qa/32/2401_2.png) [@wenjingli-qa](https://forum.solidproject.org/u/wenjingli-qa)\
**Post date:** [May 7, 2021, 9:15am UTC](https://forum.solidproject.org/t/solid-ldflex-authenticated-requests/4270/7 "2021-05-07T09:15:33Z")

</div>

Sorry,could I put in a word? I also use nodejs+express to developing back-end for an app, and i had install the library solid-node-client. I met some difficutl when i authentication for NSS-Style Pods,i had added the error and code in reply:

> [@Could i login solid pod automatically without opening the solid login page?](http://forum.solidproject.org/t/could-i-login-solid-pod-automatically-without-opening-the-solid-login-page/4260/3):
>
> thanks for your reply :smiley:I’m not developping an in-browser app.In fact,i’m working with NodeJS.I had created an express application.I find a library provides access to Solid: [GitHub - solid/solid-node-client: a nodejs client for Solid](https://github.com/solid/solid-node-client) ,but when i try to authentication for NSS-Style Pods, there a new error i didn’t find the way to solve it cry cry app.js var SolidNodeClient = require('solid-node-client'); const client = new SolidNodeClient.SolidNodeClient(); async function g…

But authentication for ESS-Style Pods is worked well.  
Thanks for reading me!

---

<div class="post-metadata">

**Author:** ![ramonvilafer](https://avatars.discourse-cdn.com/v4/letter/r/e99b99/32.png) [@ramonvilafer](https://forum.solidproject.org/u/ramonvilafer)\
**Post date:** [May 7, 2021, 1:36pm UTC](https://forum.solidproject.org/t/solid-ldflex-authenticated-requests/4270/8 "2021-05-07T13:36:40Z")

</div>

Well yes, I could try, but in this particular situation I would like to use a more _native_ approach, which, in turn, would both help me to 1) understand how Solid authentication works and 2) force me to develop a REST API to abstract the use of Solid (so it’ll become much easier to maintain and extend in the future).

I would also like to develop a java/kotlin package for this specific use case (interaction with solid pods as an storage/database system) although right now I don’t really have any idea about how I’ll do it.

Why so much work when you could just use the existing libraries and tools? Well, I think that most android developers would happily integrate Solid into their applications if there was a simple and straightforward way to do it, something that (IMO) would greatly help to kick-start the adoption of this technology.

---

<div class="post-metadata">

**Author:** ![jeffz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/jeffz/32/600_2.png) [@jeffz](https://forum.solidproject.org/u/jeffz)\
**Post date:** [May 7, 2021, 4:23pm UTC](https://forum.solidproject.org/t/solid-ldflex-authenticated-requests/4270/9 "2021-05-07T16:23:07Z")

</div>

@wenjingli-qa - I have responded to you in another thread. I am investigating the issue and will report back.
