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.

        .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")
        .preemptive().basic(UN, PSSWD)

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