干杯
我目前正在使用REST API和PHP客户端进行OAuth 2.0授权。不幸的是,我不知道如何使用PHP获取访问令牌。
我能够连接到API并通过Postman接收访问令牌。这是使它起作用的授权设置:
Type: OAuth 2.0
Add authorization data to: Request Headers
Token Name: MyToken
Grant Type: Password Credentials
Access Token URL: https://thisisaniceurl.com/oauth/token
Username: myusername
Password: P@ssword123
Client ID: ThisIsAClientId
Client Secret: 123456789-987654321-1234
Scope: <empty>
Client Authentication: Send as Basic Auth header
如何将这个请求放入PHP?这就是我所拥有的:
$AccessTokenUrl = "https://thisisaniceurl.com/oauth/token";
$Username = "myusername";
$Password = "P@ssword123";
$ClientId = "ThisIsAClientId";
$ClientSecret = "123456789-987654321-1234";
$provider = new OAuth([
'clientId' => $ClientId ,
'clientSecret' => $ClientSecret,
'urlAccessToken' => $AccessTokenUrl,
]);
$accessToken = $provider->getAccessToken($AccessTokenUrl, [
'username' => $Username,
'password' => $Password
]);
var_dump($accessToken);
不幸的是,它仅返回“ NULL”。我在做什么错了?
谢谢。 :-)