0

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.

  • Auth URL

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

  • Login UserId
user001@tenant.onmicrosoft.com
  • Hi, the question is not clear here, are you using log4j in your application and looking to get the authorization URL and sign in user id in the logs? Could you please clarify so we can help you further? – ShwetaM Jul 29 '22 at 11:15
  • Thank you, I get logs when I get redirected in Spring Boot(DefaultRedirectStrategy.java) logs, but it is in debug mode, I want to output logs in info in log4j, so I asked what code I should put to get the redirect URL to output logs. ```DEBUG Redirecting to https://login.microsoftonline.com/xxxxxxxx DefaultRedirectStrategy.java:57``` – t-kitamura Aug 02 '22 at 09:54

2 Answers2

1

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");
    }
11ohina017
  • 139
  • 8
0

Here is the sample code that can get redirect uri:

@GetMapping("azure/redirect-uri")
public String azureRedirectUri(@RegisteredOAuth2AuthorizedClient("azure") OAuth2AuthorizedClient azure) {
    return azure.getClientRegistration().getRedirectUri();
}

Other information like "client-id" can also get by "azure.getClientRegistration.getXxx()".

chenrujun
  • 126
  • 4