locked
Using elements of authenticated UserID RRS feed

  • Question

  • User23079652 posted

    Hi, I have a web forms C# site, which authenticates with internal users only.

    I'd like to be able to do two things which I haven't worked out how to do, any help would be much appreciated.

    A/ How to incorporate the users avatar OR initials in the header bar?

    B/ How to incorporate elements of a user ID within a page, such as a SQL select query (e.g. SELECT * FROM Tabl1 where KEY=USEREMAILADDRESS)

    I've tried calling the image from Microsoft Graph, but that doesn't seem to be possible.

    Thanks. Phil.

    Monday, October 14, 2019 11:22 AM

All replies

  • User409696431 posted

    What kind of authentication are you using - what do you mean "authenticates with internal users"?  Do you mean Windows Authentication or Active Directory? Other?

    For example if you are using Windows Authentication, email and avatar are not part of User.Identity.  You have pretty much three things in Identity to display on the page (or use in a query).

    <%=User.Identity.Name%>
    <%=User.Identity.IsAuthenticated%
    <%=User.Identity.AuthenticationType%>

    Tuesday, October 15, 2019 12:32 AM
  • User665608656 posted

    Hi philburns,

    According to your description , I'm not sure which authentication method you use to store user login information, Microsoft Graph's AAD authentication or Windows's AD domain authentication ?

    A/ How to incorporate the users avatar OR initials in the header bar?

    For this question, what I want to confirm is whether you want to put all users' avatars together in the header bar or the currently logged-in user, and in what form?

    B/ How to incorporate elements of a user ID within a page, such as a SQL select query (e.g. SELECT * FROM Tabl1 where KEY=USEREMAILADDRESS)

    For this one, do you want to put the acquired User ID information on the page of webform through SQL statements?

    Please elaborate on your issues and needs, as well as the current situation, so that we can solve your issues more easily.

    Best Regards,

    YongQing.

    Tuesday, October 15, 2019 8:38 AM
  • User23079652 posted

    Hi, I'm currently using Windows authentication and benefiting from the single sign in with O365, but if there's a different way I'd be happy to explore that.

    I'd like to show the current logged in user's avatar, if at all possible.

    I'm not sure about how I solve the query issue, so long as there is a way I can incorporate an element of the users ID into a SQL query, maybe by declaring the user's email (username?) as a session variable?

    Tuesday, October 15, 2019 10:16 AM
  • User409696431 posted

    I have no experience with using O365 for single sign-in.  Perhaps someone who does can help.  The obvious question is what fields about the user do you have access to, and I can't answer that.

    Tuesday, October 15, 2019 12:26 PM
  • User23079652 posted

    How does it work with graph? I presume the user ID is the same through that route?

    Tuesday, October 15, 2019 12:33 PM
  • User665608656 posted

    Hi philburns72,

    Could you please tell us how do you authenticate user , use ADFS, or use AAD connet to sync local user to AAD and use AAD to login ?

    Best Regards,

    YongQing.

    Wednesday, October 16, 2019 7:45 AM
  • User753101303 posted

    Hi,

    Seems you are using Azure Active Directory? You tried https://docs.microsoft.com/en-us/graph/api/resources/profilephoto?view=graph-rest-1.0 ?

    "Windows authentication" rather means you are configuring IIS to use your own local Active Directory.

    Wednesday, October 16, 2019 8:11 AM
  • User23079652 posted

    Yes it's using the AAD method.

    I've gone back to the 'Connected services' and I can see that there are a selection of options - none of which have been ticked.

    If I want the active user profile to retrieve the avatar, I presume that's in the user part?

    Wednesday, October 16, 2019 8:44 AM
  • User753101303 posted

    Unclear what you have done so far. The user is authenticated sucessfully and now you want to retrieve irs avatar ?

    You are using https://www.nuget.org/packages/Microsoft.Graph ? I would try to retrieve the image and wiould act based on what happens. Not tried yet but will give this a try soon ( I expect the corresponding Profile api to be surfaced with that).

    Wednesday, October 16, 2019 9:58 AM
  • User23079652 posted

    Thanks, yes that's right I'm trying to get the avatar of an authenticated user.

    I've checked the "Install-Package Microsoft.Graph -Version 1.18.0" command and it's installed.

    This bit works ok

    <a href="~/UserInfo" runat="server">You are signed in as: <%: Context.User.Identity.Name  %>

    but this line fails

    <img alt="ABC" src="https://graph.microsoft.com/v1.0/me/photo/$value" />

    I'm really not sure why that would be.

    Wednesday, October 16, 2019 10:48 AM
  • User665608656 posted

    Hi philburns72,

    but this line fails

    <img alt="ABC" src="https://graph.microsoft.com/v1.0/me/photo/$value" />

    You can not use this src to get pictures in Microsoft.Graph directly . 

    Because you need to let Microsoft.Graph know your current identity to allow you to get pictures.

    You need to use request to get the pictures in microsoft.graph in the code behind.

    You can refer to this link : Get a user

    Best Regards,

    YongQing.

    Thursday, October 17, 2019 2:35 AM