如何使用Java使用Microsoft oAuth2身份验证获取令牌 [英] how to get token using Microsoft oAuth2 authentication using Java

查看:631
本文介绍了如何使用Java使用Microsoft oAuth2身份验证获取令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用Java并放心测试API。我们的API使用Microsoft Integrated登录和oAuth2身份验证。

we are using Java and rest assured to test a API. Our API are using Microsoft Integrated login with oAuth2 authentication.

为了测试API,我们需要获取令牌并在自动化套件中使用令牌。

In order to test the API's we need to get token and use the token in the automation suite.




我们使用以下代码与Rest-Assured库获取令牌但接收302状态代码。

we are using below code with Rest-Assured libraries to get the token but receiving 302 status code.




如何使用来自Rest-Assured / Java的oAuth2或仅使用Java获取令牌? 



How do I get token using oAuth2 from Rest-Assured/Java or only from Java ? 

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());




ATDD自动化开发人员


ATDD automation developer

推荐答案

您是否可以尝试检查URL编码是否已关闭。 放心自动提供此功能但在某些情况下,使用$ b显式关闭它可能会有用$ b 给()。 urlEncodingEnabled(false)
Can you try checking if the URL encoding is off.  Rest assured provides this automatically but in some cases it may be useful to turn it off explicitly using given().urlEncodingEnabled(false).


这篇关于如何使用Java使用Microsoft oAuth2身份验证获取令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆