cancel
Showing results for 
Search instead for 
Did you mean: 

MDK Current Logged UserID in Web application

yyertuganov
Participant
0 Kudos

Dear Experts,

The app I am developing will be used both in Android and Web, where will need to identify current logged in User for processing in front end codes. My understanding we use UserID in #Application/#ClientData/UserId and it seems working correctly in Android, where it returns current users e-mail address. My problem is in Web application, where I get Empty value for this UserID. I read through some questions in the web but I couldn´t get clear answer if this is bug specifically for Web or something else.

So my 2 questions here:

1. Is it known issue/bug not being able to get UserId in Web version of MDK? If so what would be a workaround?

2. In Android as userID I get current logged users email (e.g. yyertuganov@example.com), is there way to get current logged users Login name instead (like SAP S or P ID or IAS Login id as e.g. 'S00254580' or 'YYERTUGANOV' ?

Many thanks,

Yergali

Accepted Solutions (1)

Accepted Solutions (1)

Jitendra_Kansal
Product and Topic Expert
Product and Topic Expert

#Application/#ClientData/UserId in web runtime now returns the correct value. Please choose "Preview" web runtime option while deploying MDK metadata to Cloud Foundry.

fjcarrasco
Active Participant
0 Kudos

jitendrakumar.kansal good news !!!

Is this available in "Preview" and it will be available in "production" in the future?

Jitendra_Kansal
Product and Topic Expert
Product and Topic Expert

"Production" web runtime will be updated in two weeks.

yyertuganov
Participant
0 Kudos

Thanks a lot Jitendra!!

Only one more thing, I see right now it returns current loged user, his/her email address, is there any way to access to other data like actual User ID, Name etc.

In case of Android we were accesing them thorugh GET to /mobileservices/application/${appId}/roleservice/application/${appId}/v2/Me..

Jitendra_Kansal
Product and Topic Expert
Product and Topic Expert
0 Kudos
yergaliyertuganov

Accessing other data is currently not available in web runtime.

Answers (2)

Answers (2)

fjcarrasco
Active Participant

yergaliyertuganov

I get the user ID from IAS in "id" property calling this request:

let appId = context.evaluateTargetPath('#Application/#ClientData/#Property:MobileServiceAppId');
  
let userInfoUrl = `/mobileservices/application/${appId}/roleservice/application/${appId}/v2/Me`;
            let params = { 'method': 'GET' };
            
            return context.sendRequest(userInfoUrl, params).then(r => {
                if (r && r.statusCode === 200 && r.content) {
                    const userInfo = JSON.parse(r.content.toString());
                    appSettings.setString(`${appId}-UserId`,userInfo.id);
                    appSettings.setString(`${appId}-UserName`,userInfo.userName);
                    appSettings.setString(`${appId}-UserGivenName`,userInfo.name.givenName);
                    appSettings.setString(`${appId}-UserFamilyName`,userInfo.name.familyName);
                    appSettings.setString(`${appId}-UserEmail`,userInfo.emails[0].value);
                    appSettings.setString(`${appId}-UserFullName`,`${userInfo.name.givenName} ${userInfo.name.familyName}`);
                    return Promise.resolve();
                }
            },
            (error) => {
                console.log(error.toString());
            });     

yyertuganov
Participant
0 Kudos

Francisco thanks a lot for your help!

I just have tried your code, it does work for Mobile/Android, however returns error (404 Not Found) in Web version. Couple of questions:

1. Do you use the same script for Web or only utilize for Android?

2. In Android it does return data, however in all 3 fields as id, userName and emails[0].value it gives me my e-mail address, but not actual values set in IAS for UserID and Login Name... First name and Last name are correct values from IAS. Maybe should I change something in IAS, where it seems like passing e-mail address for all 3 fields...

Many thanks,

Yergali

fjcarrasco
Active Participant
0 Kudos

yergaliyertuganov

I use this script only for mobile platform.

I'm sorry but I can't help you with IAS because I didn't do the set up and I don't really know how it works.

I'm going to ask the person who did it.

Kiko

yyertuganov
Participant
0 Kudos

Thanks a lot Francisco!

fjcarrasco
Active Participant
0 Kudos

jitendrakumar.kansal Is there any advance about this known issue ?

My sap support ticket was closed automatically and solution attached was MDK 6.1.1.

I have tryed for web the same I do to get the user for mobile however still is not working:

 let appId = context.evaluateTargetPath('#Application/#ClientData/#Property:MobileServiceAppId');
    let userInfoUrl = `/mobileservices/application/${appId}/roleservice/application/${appId}/v2/Me`;
    let params = { 'method': 'GET' };

    return context.sendRequest(userInfoUrl, params).then(r => {
        if (r && r.statusCode === 200 && r.content) {
            const userInfo = JSON.parse(r.content.toString());
            alert(userInfo.id + " " + userInfo.userName);
            return Promise.resolve();
        }
    },
        (error) => {
            console.log(error.toString());
        });

Thanks

Kiko

Jitendra_Kansal
Product and Topic Expert
Product and Topic Expert

fjcarrasco

We are still investigating on this issue, we are hoping to provide you a solution soon.

Jitendra_Kansal
Product and Topic Expert
Product and Topic Expert

1. This is a known problem, we will fix it.

2. The UserId value is coming from the identity provider set up in your BTP subaccount. Are you using the standard SAP IdP or your own IdP?

yyertuganov
Participant
0 Kudos

Jitendra,

Thanks a lot for your response. Few comments:

1. Do you know more less when that fix for Web version will be out? This year or next?

2. We will be using SAP IAS service, where I have an account with my e-mail address, Login name and User Id. I have alreaded did onboarding with this account in Android and done some tests, where when I query #Application/#ClientData/UserId it always returns my e-mail address. Is there some settings I have to change or in IAS, BTP, Mobile Services o within my codes to get an User Id or Login name in IAS?

Thank you,

Yergali

Jitendra_Kansal
Product and Topic Expert
Product and Topic Expert
0 Kudos

1. Our experts are looking into it, i can share an update once issue is fixed. You are welcome to create a support ticket if needed.

2. I think best is to check with IAS team on this.

fjcarrasco
Active Participant
0 Kudos

Hello.

I need my app can run in Web environment and I need to get the user Id as well in order to show and work with the information based on the user who is logged.

Is there any advance with this issue?

Thanks

Kiko