azure-active-directoryazure-spring-cloud

How do I get the authentication URL and user ID using spring-cloud-azure-starter-active-directory?


How do I get the authentication URL and user ID using spring-cloud-azure-starter-active-directory?

https://learn.microsoft.com/en-us/azure/developer/java/spring-framework/configure-spring-boot-starter-java-app-with-azure-active-directory

I understand that AD authentication is possible with the source code of the following URL, but I would like to output the user and authentication URL in the log.

https://login.microsoftonline.com/{tenantID}/oauth2/v2.0/authorize?response_type=code&client_id={clinet_id}

user001@tenant.onmicrosoft.com

Solution

  • Redirects are unknown, but user IDs can be output in the following format

    
        @GetMapping("Adimn")
        public ModelAndView Adimn(HttpServletRequest request) {
        
            try {
                String userId = request.getUserPrincipal().getName();   
                log.info(userId);
    
            return new ModelAndView("redirect:" + "/index");
        }