Menu

Getting Current user in REST/JSON

2020-07-30
2020-08-03
  • Green Arrow

    Green Arrow - 2020-07-30

    HI, I am working with webservice for portal user in itop 2.7
    1)
    I tried to auth
    localhost/webservices/rest.php?version=1.0&json_data={"operation":"core/check_credentials","user":"portaluser","password":"Portal@123"}

    returned me with
    {
    "code": 0,
    "message": null,
    "user": {},
    "authorized": true
    }

    when I tried to return userdetails using UserRights::FindUser($user) user returned empty as "user": {},

    Then i printed the result in UserRight class itself object was available for portal user itself, sadly It was admins profile not the one i requested for. My question is how do I make login via webservice and how do i Get the ID of the profile ??

    UserLocal Object
    (
    [m_oPasswordValidity:protected] =>
    [oContactObject:protected] =>
    [m_iFormId:protected] =>
    [aFieldsMap:protected] =>
    [bAllowWrite:protected] =>
    [bAllowDelete:protected] =>
    [m_datCreated:protected] =>
    [m_datUpdated:protected] =>
    [m_bIsInDB:protected] => 1
    [m_iKey:protected] => 1
    [m_aCurrValues:DBObject:private] => Array
    (
    [contactid] => 1
    [last_name] => My last name
    [first_name] => My first name
    [email] => my.email@foo.org
    [org_id] => 1
    [login] => admin
    [language] => EN US
    [status] => enabled
    [reset_pwd_token] => ormPassword Object
    (
    [m_sHashed:protected] =>
    [m_sSalt:protected] =>
    )

    [finalclass] => UserLocal
    [friendlyname] => admin
    [contactid_friendlyname] => My first name My last name
    [contactid_obsolescence_flag] =>
    [org_id_friendlyname] => GOOGLE INC.
    [org_id_obsolescence_flag] =>
    )

    [m_aOrigValues:protected] => Array
    (
    [contactid] => 1
    [last_name] => My last name
    [first_name] => My first name
    [email] => my.email@foo.org
    [org_id] => 1
    [login] => admin
    [language] => EN US
    [status] => enabled
    [reset_pwd_token] => ormPassword Object
    (
    [m_sHashed:protected] =>
    [m_sSalt:protected] =>
    )

    [finalclass] => UserLocal
    [friendlyname] => admin
    [contactid_friendlyname] => My first name My last name
    [contactid_obsolescence_flag] =>
    [org_id_friendlyname] => GOOGLE INC.
    [org_id_obsolescence_flag] =>
    )

    [m_aExtendedData:protected] =>
    [m_bDirty:DBObject:private] =>
    [m_bCheckStatus:DBObject:private] => 1
    [m_bSecurityIssue:protected] =>
    [m_aCheckIssues:protected] =>
    [m_aCheckWarnings:protected] =>
    [m_aDeleteIssues:protected] =>
    [m_bFullyLoaded:DBObject:private] =>
    [m_aLoadedAtt:DBObject:private] => Array
    (
    [contactid] => 1
    [last_name] => 1
    [first_name] => 1
    [email] => 1
    [org_id] => 1
    [login] => 1
    [language] => 1
    [status] => 1
    [reset_pwd_token] => 1
    [finalclass] => 1
    [friendlyname] => 1
    [contactid_friendlyname] => 1
    [contactid_obsolescence_flag] => 1
    [org_id_friendlyname] => 1
    [org_id_obsolescence_flag] => 1
    )

    [m_aTouchedAtt:protected] => Array
    (
    )

    [m_aModifiedAtt:protected] => Array
    (
    )

    [m_aPreviousValuesForUpdatedAttributes:protected] =>
    [m_aSynchroData:protected] =>
    [m_sHighlightCode:protected] =>
    [m_aCallbacks:protected] => Array
    (
    )

    )

    . How do I solve this ??

    also the :current_contact_id is always 1

     

    Last edit: Green Arrow 2020-07-30
  • Pierre Goiffon

    Pierre Goiffon - 2020-08-03

    Hello,

    Seems like a duplicate of this thread, am I right ?
    Please don't post duplicates...

    Reading the API documentation you'll see that both auth_user and auth_pwd parameters must be passed directly, at the same level as json_data. You sent them in the json_data parameter, so in the wrong place.

     
  • Green Arrow

    Green Arrow - 2020-08-03

    yes that was my query too.

     
  • Pierre Goiffon

    Pierre Goiffon - 2020-08-03

    Ok thanks

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.