How to get the current user name in Provider hosted app using appOnlyAccessToken

Hi, 
Please help me, how to get the HostWeb UserName in Provider Hosted App
i have Provider hosted App, and Anonymous Authentication is enabled on AppWeb, using appOnlyAccessToken
Below code does not return current user who Log in in hostweb, it is returning
SharePoint App (app@sharepoint)
Web web = clientContext.Web;
clientContext.Load(web);
clientContext.ExecuteQuery();
clientContext.Load(web.CurrentUser);
clientContext.ExecuteQuery();
clientContext.Web.CurrentUser.LoginName;
Below code gives a blank name when Anonymous Authentication is enabled, if Anonymous Authentication is disabled
app prompts for credentials 
HttpContext.Current.User.Identity.Name
Thanks
Ram

Hi,
Since you are using a provider Hosted app if you want to get the current logged in name than do not use AppOnlyAccessToken else use AccessToken which is App + user Context AccessToken.
then 
Web web = clientContext.Web;
clientContext.Load(web);
clientContext.ExecuteQuery();
clientContext.Load(web.CurrentUser);
clientContext.ExecuteQuery();
clientContext.Web.CurrentUser.LoginName;will return proper user Name.
HttpContext.Current.User.Identity.Name will never return the user as this object is related to IIS server of your App Server not sharepoint.you should set this as Anonymous in case of provider hosted app.you can download the below sample which uses the AccessToken which has user name in it.https://code.msdn.microsoft.com/Working-provider-hosted-8fdf2d95
Whenever you see a reply and if you think is helpful,Vote As Helpful! And whenever you see a reply being an answer to the question of the thread, click Mark As Answer

Similar Messages

  • How to get the current user name of the host who is occupying a specific VM?

    I'm developing a winform app with c# code to manage Hyper-V. I need to remind someone if he/she would take a VM which has already been occupied by others.
    Is there any powershell cmd or WMI interface to get the current user of a specific VM?
    Thanks!

    Hiya,
    from cmd there are quser(Query user) and qwinsta(Query Session)
    which should give you that. Don't know how you can incoorperate that in C#, but that should give you something to work with :)
    https://technet.microsoft.com/en-us/library/cc785434.aspx
    https://technet.microsoft.com/en-us/library/cc788125.aspx

  • How To get SharePoint logedin user email in provider hosted app

    Hi
    I am using Amazon cloud to host my provider hosted app. App is developed using chrome control and app is registered in SharePoint Online.
    can any one explain how to get email Id of logged in user in SharePoint online from provider hosted App.
    Regards
    Kaps

    Hi,
    Please refer to the following article it has complete information how to get user details.
    How to: Get user identity and properties in SharePoint 2013
    Using PeopleManager, we can get the emailID.
    PeopleManager peopleManager = new PeopleManager(clientContext);
    PersonProperties personDetails = peopleManager.GetMyProperties();
    clientContext.Load(personDetails, personsD => personsD.AccountName, personsD => personsD.Email, personsD => personsD.DisplayName);
    clientContext.ExecuteQuery();
    Please mark it answered, if your problem resolved.

  • How to get the current schema name

    Hi,
    Can anybody please tell me how to get the current schema name, there is some inbuilt function for this,but i am not getting that. Please help me.
    Thanks
    Jogesh

    ok folks, I found the answer at Tom's as usual.
    http://asktom.oracle.com/tkyte/who_called_me/index.html
    I rewrote it into a function for kicks. just pass the results of DBMS_UTILITY.FORMAT_CALL_STACK to this function and you will get back the owner of the code making the call as well some extra goodies like the name of the code and the type of code depending on the parameter. This ignores the AUTHID CURRENT_USER issues which muddles the schemaid. Quick question, does the average user always have access to DBMS_UTILITY.FORMAT_CALL_STACK or does this get locked down on some systems?
    cheers,
    paul
    create or replace
    FUNCTION SELF_EXAM (
       p_call_stack VARCHAR2,
       p_type VARCHAR2 DEFAULT 'SCHEMA'
    ) RETURN VARCHAR2
    AS
       str_stack   VARCHAR2(4000);
       int_n       PLS_INTEGER;
       str_line    VARCHAR2(255);
       found_stack BOOLEAN DEFAULT FALSE;
       int_cnt     PLS_INTEGER := 0;
       str_caller  VARCHAR2(30);
       str_name    VARCHAR2(30);
       str_owner   VARCHAR2(30);
       str_type    VARCHAR2(30);
    BEGIN
       str_stack := p_call_stack;
       -- Loop through each line of the call stack
       LOOP
         int_n := INSTR( str_stack, chr(10) );
         EXIT WHEN int_cnt = 3 OR int_n IS NULL OR int_n = 0;
         -- get the line
         str_line := SUBSTR( str_stack, 1, int_n - 1 );
         -- remove the line from the stack str
         str_stack := substr( str_stack, int_n + 1 );
         IF NOT found_stack
         THEN
            IF str_line like '%handle%number%name%'
            THEN
               found_stack := TRUE;
            END IF;
         ELSE
            int_cnt := int_cnt + 1;
             -- cnt = 1 is ME
             -- cnt = 2 is MY Caller
             -- cnt = 3 is Their Caller
             IF int_cnt = 1
             THEN
                str_line := SUBSTR( str_line, 22 );
                dbms_output.put_line('->' || str_line);
                IF str_line LIKE 'pr%'
                THEN
                   int_n := LENGTH('procedure ');
                ELSIF str_line LIKE 'fun%'
                THEN
                   int_n := LENGTH('function ');
                ELSIF str_line LIKE 'package body%'
                THEN
                   int_n := LENGTH('package body ');
                ELSIF str_line LIKE 'pack%'
                THEN
                   int_n := LENGTH('package ');
                ELSIF str_line LIKE 'anonymous%'
                THEN
                   int_n := LENGTH('anonymous block ');
                ELSE
                   int_n := null;
                END IF;
                IF int_n IS NOT NULL
                THEN
                   str_type := LTRIM(RTRIM(UPPER(SUBSTR( str_line, 1, int_n - 1 ))));
                 ELSE
                   str_type := 'TRIGGER';
                 END IF;
                 str_line  := SUBSTR( str_line, NVL(int_n,1) );
                 int_n     := INSTR( str_line, '.' );
                 str_owner := LTRIM(RTRIM(SUBSTR( str_line, 1, int_n - 1 )));
                 str_name  := LTRIM(RTRIM(SUBSTR( str_line, int_n + 1 )));
              END IF;
           END IF;
       END LOOP;
       IF UPPER(p_type) = 'NAME'
       THEN
          RETURN str_name;
       ELSIF UPPER(p_type) = 'SCHEMA.NAME'
       OR    UPPER(p_type) = 'OWNER.NAME'
       THEN
          RETURN str_owner || '.' || str_name;
       ELSIF UPPER(p_type) = 'TYPE'
       THEN
          RETURN str_type;
       ELSE
          RETURN str_owner;
       END IF;
    END SELF_EXAM;

  • How to get the Current User on the UI page?

    All,
    Could you please let me know how to get the Current user on the UI input page , i need to display the current user ID when some one clicks the submit button, i want o get the current user to display in the javascript alert box.
    Edited by: 951930 on Oct 24, 2012 12:21 PM

    lucky,
    my schema has already defined for
    <user mapField="USER_ID" default="%CurrentUser"/>
    and in my UI page
    <td oraLabel="user"></td><td oraField="user" id="userId" ></td>
    and my javascript
    function showUserId () {                        
    var curUser = document.getElementById('userId').value;
    alert(curUser);
    and i have called this function on my submit button, but i am not able to get Current Logged User ID value to show in the alert nor able to show the current logged user on the UI page.
    my requirement is on custom UI page i need to show Current Logged User in one corner of the page and also need to show the same user in alert when he submits the button.
    Appreciate for the help.
    Edited by: 951930 on Oct 25, 2012 8:42 AM
    Edited by: 951930 on Oct 25, 2012 9:06 AM

  • How to get the current user logon to portal?

    Hi Gurus,
    How to get the current user who logged into portal.
    I have a webdynpro requirement where in which I have to get the current user id who loggedinto portal which will be the input parameter of the BAPI(adaptive RFC model) which will return me employee number of the particular user.
    Can anyone send me the code to retrive the user id through webdynpro application..........
    Pts will be rewarded for useful inputs......
    Thanks in Advance,
    Dharani

    Hi Dharani,
    Using UMEfactory u can do that...
    1. create one input field,
    2. create one attribute called Uid
    3. assign Uid attribute to the input field
    4. type the following code in Doinit() method
                String uid = wdContext.currentContextElement().getUid();
         try {
         IUser user = UMFactory.getUserFactory().
         getUserByLogonID(uid);
         String userName = user.getDisplayName();
         } catch (UMException ex) {
          e.toString(); 
    5. after that go to Portal create one iview assign to particular user. then u get into the user details...
    thats it
    Regards,
    P.Manivannan

  • How to get the current function name in java

    How to get the current function name in java.
    In c it is done as
    printf("%s",__func__);
    Thanx in advance.

    j0o wrote:
    System.out.println("Class Name: " + new Exception().getStackTrace()[0].getClassName() +
    "/n Method Name : " + new Exception().getStackTrace()[0].getMethodName() +
    "/n Line number : " + new Exception().getStackTrace()[0].getLineNumber());
    I pointed the OP at this approach yesterday in one of his multi-posts. I still have not been given my Dukes!

  • How to find the current User Name and stored in which table

    In which table the current user name (Login) is stored?

    Hi Mohanapriya
    The query provided by Gordon can not run on query generator as the $USER is a runtime variable.
    You need to save it to a query then use it in a FMS(Formatted Search.)
    Just open a form(ex:sales order ), click the field in which you want to show the user name,
    then press ****+F2 or Tools->Search Function->Define,
    Search by Saved query,then assign the save query to the field.
    After that ,you can run the FMS(shift+F2) to get the current user info.
    Regards,
    Syn Qin
    SAP Business One Forums Team

  • How to get the current class name in static method?

    Hi,
    I'd like to get the current class name in a static method. This class is intended to be extended. So I would expect that the subclass need not to override this method and at the runtime, the method can get the subclass name.
    getClass() doesn't work, because it is not a static method.
    I would suggest Java to make getClass() static. It makes sense.
    But in the mean time, does anybody give an idea to work around it?
    Thank you,
    Bill

    Why not create an instance in a static method and use getClass() of the instance?
    public class Test {
       public static Class getClassName() {
          return new Test().getClass();

  • Uix frameset - how to get the current frame name?

    I have a frameset with 3 different frames in it. a top, center and bottom.
    There is a menu in the top frame that changes the contents of the center or bottom frame.
    How can I get the value of the frame name for the current frame into a bound value like a httpsession or page?
    for example if I change the center frame to "listadmin.uix" how can I load a bound value with the frames new source?
    Is there a way to pass javascript to a boundvalue? I could get the frames new properties from javascript

    In Jdev 9.0.3 you could do something like this:<frameBorderLayout>
    <start>
       <frame name="sideFrame">
        <boundAttribute name="source">
         <ctrl:pageURL name="sideFramePage">
          <ctrl:properties>
           <ctrl:property key="currentFrame"
                          value="sideFrame"/>
          </
         </
        </
       </
    </
    </then in startFramePage.uix you can access the current frame name by doing:<styledText data:text="currentFrame@ctrl:page"/>

  • How to get the current User Id

    Hi,
    is there any system variable containing the current "user code"
    because, based on current user code, i would like to get the branch from OUSR, so that, one query can display only those records pertaining to that branch.
    Thanks & Regards,
    Kr

    Hi
    You can create a formatted search to get and the following query:
    SELECT T0.U_NAME FROM OUSR T0 WHERE INTERNAL_K = $[USER]
    Paulo Calado
    SAP Business One Forums Team

  • Indesign CS3: How to get the current document name?

    Hallo!
    How do I get the name of the current document loaded in Indesign?
    Thanks,
    Alois Blaimer

    ...Plese Ignore the last post...<br /><br />docRef is the UIDRef of the document. Plese consider the following code<br /><br />IDocument *docFrom = Utils<ILayoutUIUtils>()->GetFrontDocument(); <br />if (docFrom == NULL ) <br />    break; <br />UIDRef  docRef = GetUIDRef(docFrom )); <br /><br />InterfacePtr<IDocument> iDocument (docRef, IID_IDOCUMENT); <br />if(iDocument == nil) <br />   break; <br /><br />PMString docName; <br />iDocument->GetName(docName);

  • How to get the current view name is displaying?

    Hi Experts,
    I have a requirement that I have to know the current view is displaying. At the header of the page, there is a component (BTCHIST) which is fix and common for the all others. It has a button called Finish. When the user clicks on it, it has a different behavior depending on the current view.
    Does anyone know any method in order to get this information? I searched up in CRM_UI_FRAME, however I didnu2019t find anything.
    Regards,
    André

    Hi,
    You need to redefine the method IF_BSP_WD_HISTORY_STATE_DESCR~GET_STATE_DESCRIPTION of the controller class to change the view description. Unfortunately, the effort is huge and we cannot do it dynamically and needs to be done for each view in question.
    Regards
    Prasenjit

  • How to get the current EAR name in a servlet ?

    Greetings,
    In a servlet, I need to retrive the EAR name. Using the ServerRuntimeMBean I can retrieve the list of the applications via the ApplicationsRuntime attribute. But I don't find any CurrentApplicationRuntime attribute or something similar. Many thanks in advance for any help.
    Kind regards,
    Nicolas

    j0o wrote:
    System.out.println("Class Name: " + new Exception().getStackTrace()[0].getClassName() +
    "/n Method Name : " + new Exception().getStackTrace()[0].getMethodName() +
    "/n Line number : " + new Exception().getStackTrace()[0].getLineNumber());
    I pointed the OP at this approach yesterday in one of his multi-posts. I still have not been given my Dukes!

  • How to add the current user to a people picker using javascript coding in document library

    Hi Everyone,
    This is my scenario,
    I have a document library,for this if any user uploads a document,there we have three content types(Ex:content1,content2,content3)
    if the uploaded user is from content 1(here we have four columns name,assigned to ,status,published to) after uploading the document the document has to be updated.so when the document is updated by the user then automatically the published filed people
    picker has to be filled up with the current user name this is done by using java script object model programming.
    i am stuck with this can anyone help me..............
    thanks in advance
    Ramu

    Hi,
    I understand that you want to set a people picker field value automatically to current user. You can use these ECMA scripts on your EditForm.aspx page. Edit the page in SharePoint designer and add the code before a </asp:Content> tag.
     <script type="text/javascript">
    var context = null;
     var web = null;
     var currentUser = null;
    ExecuteOrDelayUntilScriptLoaded(GetUserLoginName, "sp.js");
    function GetUserLoginName() {
    context = new SP.ClientContext.get_current();
     web = context.get_web();
     this._currentUser = web.get_currentUser();
     context.load(this._currentUser);
     context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod),
    Function.createDelegate(this, this.onFailureMethod));
     function onSuccessMethod(sender, args) {
     var today = new Date();
     alert('Name:' + this._currentUser.get_title() + '\n Login:' + this._currentUser.get_loginName()); document.getElementById('ctl00_m_g_9b4b3950_80d8_4e6e_b2fa_241b727d83d4_ctl00_ctl02_ctl00_ctl02_ctl00_ctl00_ctl04_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_upLevelDiv').innerHTML=this._currentUser.get_title();//you
    need to change the ID here to you people picker field ID. You can get the id for this field with the help of IE developer tool.
     function onFaiureMethod(sender, args) {
     alert('request failed' + args.get_message() + '\n' + args.get_stackTrace());
     </script>
    For more information, please refer to this site:
    Get current user’s LoginName Ecmascript Sharepoint 2010:
    http://www.learningsharepoint.com/2011/05/18/get-current-users-loginname-ecmascript-sharepoint-2010/
    Thanks,
    Entan Ming
    Entan Ming
    TechNet Community Support

Maybe you are looking for

  • Can't Open Project Recovered With Data Rescue

    Hi All, Stupid me, I trashed a project file and emptied the Trash. I had forgotten that a FCP sequence was referencing the DV files contained in that project package. I had no backup of the DV files (please, no preaching - I learned my lesson). I was

  • PC Expert Day June 1st and 2nd

    On behalf of all of the HP experts, we would like to thank you for coming to the Forum to connect with us. We hope you will return to the notebook and desktop boardsand share your expereinces -- both the good and the bad. We will be holding more of t

  • Why do I have to sign into my homepage every time I click the home tab??

    every time I click on the HOME icon, I get my basic webpage that asks me to sign in. why is this happening?? the att.yahoo page gives the option of "keep me signed in for 2 weeks unless I sign out" & I have this box checked. I was using IE & Chrome u

  • Missing required input property error in insert attachment

    Hi, Im getting this following error some times not all times when i tring to insert attachment files to campaign object <ErrorMessage>Missing required input property "Handle"(SBL-ODS-00242)</ErrorMessage> please give some solution Thanks, Sathis Kuma

  • How much is it to fix cracked macbook pro retina display in UK?

    I stepped on the corner of my macbook pro 13" retina display and the screen has cracked and there is a black square in the corner where the screen is broken. I was wondering from others who have had the same experience how much is it to have the scre