azure-sdk-for-java icon indicating copy to clipboard operation
azure-sdk-for-java copied to clipboard

[QUERY] How to discover user is logged in programmatically?

Open bergmp opened this issue 1 year ago • 4 comments

Query/Question How to discover user is logged in programmatically? If the user has already logged in using Azure AD, my app will not require authentication.

Why is this not a Bug or a feature Request? It is a question

Setup (please complete the following information if applicable):

  • OS: Linux
  • IDE: IntelliJ
  • Library/Libraries: com.azure.spring:spring-cloud-azure-starter-active-directory:4.2.0

Information Checklist

  • [X] Query Added
  • [X] Setup information Added

bergmp avatar Aug 02 '22 20:08 bergmp

Thank you for your feedback. This has been routed to the support team for assistance.

ghost avatar Aug 02 '22 22:08 ghost

Hi @bergmp , I think there are 3 ways to achieve this function, please try to follow this doc https://dzone.com/articles/how-to-get-current-logged-in-username-in-spring-se

moarychan avatar Aug 05 '22 10:08 moarychan

I believe I did not make myself clear.

I think that link you suggested assumes my spring app started user authentication, but authentication occurred outside my spring app. Am I right?

For example, the user logged in Microsoft Stream using Microsoft web interface. Is there any endpoint at Microsoft that my spring app can call in order to verify that a user is logged?

Em sex., 5 de ago. de 2022 07:17, Moary Chen @.***> escreveu:

Hi @bergmp https://github.com/bergmp , I think there are 3 ways to achieve this function, please try to follow this doc https://dzone.com/articles/how-to-get-current-logged-in-username-in-spring-se

— Reply to this email directly, view it on GitHub https://github.com/Azure/azure-sdk-for-java/issues/30245#issuecomment-1206286067, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQH2RTKIG7UJX5MB6DA4F53VXTS4BANCNFSM55MONFKQ . You are receiving this because you were mentioned.Message ID: @.***>

bergmp avatar Aug 06 '22 01:08 bergmp

Hi @bergmp , thanks for your update!

I think that link you suggested assumes my spring app started user authentication, but authentication occurred outside my spring app. Am I right?

Yes, each application integration on top of Spring Security, the ways of the previous comment are the right to get the logged user programmatically, no matter whether the user authentication process is done in local or outside of your app(such as Azure AD (Authentication and authorization server).

For example, the user logged in Microsoft Stream using Microsoft web interface. Is there any endpoint at Microsoft that my spring app can call in order to verify that a user is logged?

No, I am not sure there's an Azure AD endpoint to verify the user login status. If the user has already logged in using Azure AD, when the user initiates another OAuth2 client authorization code flow, the OAuth2 authorization code flow will skip the user authentication phase and continue with the rest of the process, with no need to log in again.

I assume you have two applications registered in Azure AD, if the user has logged in to application A, then you can access APIs of application B without the second authentication in Azure AD, you can try this sample project aad-web-application, is this your scenario?

moarychan avatar Aug 10 '22 01:08 moarychan

@bergmp Thanks for reaching out to us and reporting this issue. Could you please let us know if you had a chance to look at the above comment and try the suggested plan? Awaiting your reply.

navba-MSFT avatar Aug 18 '22 03:08 navba-MSFT

@bergmp I wanted to do quick follow-up to check if you had a chance to look at the above comment. Please let us know if you had any update on the above suggestion. Awaiting your reply.

navba-MSFT avatar Aug 22 '22 04:08 navba-MSFT

Thanks for your support @moarychan.

bergmp avatar Aug 23 '22 12:08 bergmp