none
How to get current logged in user in Provider hosted app with AppOnly permissions

    Question

  • Hi,

    I have created a Provider hosted app and set the Permissions as AppOnly in AppManifest.xml.

    I need to get the current logged in user in the Provider hosted app. How do I get that? 

    Any ideas?


    Prateek Srivastava

    mercredi 11 juillet 2018 15:42

Toutes les réponses

  • Hi,

    You could get current user by.

    clientContext.Web.EnsureUser(HttpContext.Current.User.Identity.Name)

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    jeudi 12 juillet 2018 03:40
  • But HttpContext.Current.User.Identity.Name would give me the name of the person who is logged in to the app. Can I fetch the name of the user with whose credentials SharePoint is logged on

    Prateek Srivastava

    jeudi 12 juillet 2018 04:55
  • Hi,

    For AppOnly add-in, the app use app@sharepoint account, it works as service account per my knowledge.

    • AllowAppOnlyPolicy executes code based on the permissions granted to the SharePoint Add-in, not on behalf of another user who has the appropriate permissions to perform an operation.

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    jeudi 12 juillet 2018 05:26
  • Is it possible to login with another user in the provider hosted app other than who is logged on to SharePoint?

    Prateek Srivastava

    vendredi 13 juillet 2018 07:07
  • Hi,

    This is by design action, you could try to specify the authentication directly.

    ClientContext ctx = new ClientContext(siteUrl);
    NetworkCredential credentials = new NetworkCredential("user", "password", "domain"); 
    ctx.Credentials = credentials;

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    vendredi 13 juillet 2018 07:49
  • Passing the user's credentials is not recommended. I believe

    Prateek Srivastava

    vendredi 13 juillet 2018 08:20
  • Hi,

    It’s just workaround,if you need high permission other than current user, just use add-in only policy.

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    vendredi 13 juillet 2018 08:50