Technical Articles
Getting BTP user information in AppGyver
Introduction
Are you using the BTP Authentication feature in your AppGyver app and you want to know who is using the application?
In this guide I will explain quickly how to get the logged-in user information as email, first name or last name.
Steps
- Create a REST API data source
- Define a data variable
- Display user data
- Create a REST API data source
Go to the DATA tab and create an AppGyver classic data entity -> REST API direct integration.
Call the data source userApi
AppGyver classic data entity – REST API
Set the settings to:
Resource ID: userAPI
Resource URL: user-api/currentUser
BASE userApi
Define the GET RECORD (GET) without an URL Placeholder and remove the /{id} from the Relative path.
get Record (GET)
Go to the SCHEMA Tab and create the following schema by clicking ADD Property.
Add schema properties
2. Define a data variable
Add a new data variable for the userAPI as data variable type “Single data record” and modify the logic that it just get the records and set the data variable. Remove the delay part.
data variable userApi
3. Display the user information
Now you can use the data variable userApi to display the logged-in user information.
Bind text field to data variable
Final result
This is nice ... thanks for adding ... works like a charm
What is scopes for? I didn't get anything returned.
I found this in the documentation of the api. Scopes are related to the permissions a user needs to access a resource. This property holds the required scopes to access the target path. Access is granted if the user has at least one of the listed scopes. Note: Scopes are defined as part of the xsuaa service instance configuration. You can use
ias
as authenticationType and xsuaa scopes for authorization if the application router is bound to both (ias
andxsuaa
)."Hi Marc,
We spoke about this as a limitation early this month during the BTP workshop but delighted to see it no more a limitation. I will try this and let you know.
Regards,
Aruljothi Arumugam
Hi,
I am having issue retrieving BTP user information after the app has been deployed to appgyverapp.black or BTP. user-api path shows Error 404 not found if I launch it from appgyverapp.black domain or BTP as HTML5 Application.
Thanks.
Hi Boo Siong Khoo ,
can you try to use as a Resource URL: user-api/currentUser without the "/" before user-api.
I just updated the blog to it.
Best regards,
Marc
I am trying to get the user information in the new SAP Build Apps version and am having trouble (just in preview). It works perfectly in the old SAP AppGyver version but not the new one. Is this a known issue or am I doing something wrong. I tried without / but that removed the error but it returned HTML:
Hi Daniel,
I am also getting the same issue. Did you get any solution for this?
Thanks,
Vik
I believe this relates to the fact that you must deploy an IAS tenant, and it no longer works because of that. I assume they are working to bring this back (technically, I'm not sure this feature was officially rolled out)
Thanks Daniel!
do I have to deploy app to BTP only can return user detail with user api or inside sap build will do? I've followed your guide but I couldn't get anything in sap build.
However, i'm getting status code 200 and the response is this:
Hi @Derrick Chuah did you find any fix on this?
Yes, you can only get response (user api) to deployed app, not in SAP build.
So if deploy the above app as is should work without any dependency?
Yes correct : ) at least that's work for me.
Hello,
use the "/" before the user-api/CurrentUser and you can access the user details (even in Build Apps Preview) 🙂
Resource URL: /user-api/currentUser
Quick Update:
In SAP Build Apps you don't need a REST API anymore to access the user information. You can directly use the formulas systemVars.currentuser:
Best regards,
Marc