Java Rest Assured how to get token from Microsoft oAuth2

I am trying below code to get token for a API using Microsoft oAuth2 authentication and receiving response code 302 instead of 200.

RestAssured.given()         
        .relaxedHTTPSValidation()            
        .redirects().follow(false)        
        .param("Auth URL", AUTHORITY1)
        .param("Access Token URL", ACCESSURL)
        .param("Client ID", CLIENT_ID)
        .param("Client Secret", CS)
        .param("Scope", "read")
        .param("Grant Type", "Client Credentials")
        .auth()
        .preemptive().basic(UN, PSSWD)
        .when()
        .redirects().follow(false)
        .get(URL).statusCode());

What is wrong with the code and How do I authenticate and get the token from Microsoft oAuth2 authentication using Java or java - RestAssured ?