Twinfield API OAuth2.0 getaccessToken php Twinfield/Twinfield
我目前正在尝试设置Twinfield API,当使用php Twinfield/Twinfield库时,它应该非常简单。但有一件事我不完全明白 这是我的密码:Twinfield API OAuth2.0 getaccessToken php Twinfield/Twinfield,php,laravel,api,oauth-2.0,twinfield,Php,Laravel,Api,Oauth 2.0,Twinfield,我目前正在尝试设置Twinfield API,当使用php Twinfield/Twinfield库时,它应该非常简单。但有一件事我不完全明白 这是我的密码: $provider=新的OAuthProvider([ 'clientId'=>'someClientId', 'clientSecret'=>'someClientSecret', '重定向URI'=>'https://example.org/' ]); $accessToken=$provider->getAccessToken(“授
$provider=新的OAuthProvider([
'clientId'=>'someClientId',
'clientSecret'=>'someClientSecret',
'重定向URI'=>'https://example.org/'
]);
$accessToken=$provider->getAccessToken(“授权代码,[“代码”=>…]);
$refreshToken=$accessToken->getRefreshToken();
$office=\PhpTwinfield\office::fromCode(“someOfficeCode”);
$connection=new\PhpTwinfield\Secure\OpenIdConnectAuthentication($provider,
$refreshToken,$office);
$accessToken需要点上的东西,某种代码。我不确定那应该是什么
我希望有人能帮助我。已经谢谢你了
我仍然坚持oauth2设置。。。提供商似乎拥有它需要的所有信息。它返回检索accessToken所需的代码。但是,尝试使用以下代码获取一个:
$accessToken = $provider->getAccessToken('authorization_code',
['code' => $_GET['code']]);
这将返回“无效的授权”。
我已尝试重置我的clientSecret。。。但这没有帮助。
我希望有人能进一步帮助我。要访问Twinfield API,用户必须经过身份验证。您可以通过指定用户名和密码或使用OAuth2来实现这一点。使用OAuth2时,将身份验证委托给所谓的OAuth提供程序。用户经过身份验证后,提供商将用户的浏览器重定向到应用程序中的端点(
redirectUri
)。应用程序接收到的请求有一个GET参数,名为code
。然后,您的应用程序将使用其clientId
和clientSecret
和HTTP POST将代码交换为令牌。这意味着您的应用程序必须在OAuth2提供商处注册,以便提供商(例如github、facebook、google等)可以验证客户端凭据并返回令牌。您必须配置提供程序
变量以指向您连接的OAuth提供程序
$provider = new OAuthProvider([
'clientId' => 'XXXXXX', // The client ID assigned to you by the provider
'clientSecret' => 'XXXXXX', // The client password assigned to you by the provider
'redirectUri' => 'https://example.com/your-redirect-url/',
'urlAuthorize' => 'https://login.provider.com/authorize', //where the user's browser should be redirected to for triggering the authentication
'urlAccessToken' => 'https://login.provider.com/token', //where to exchange the code for a token
'urlResourceOwnerDetails' => 'https://login.provider.com/resource' //where to get more details about a user
]);
// If we don't have an authorization code then get one
if (!isset($_GET['code'])) {
// Fetch the authorization URL from the provider
// Redirect the user to the authorization URL.
}
Twinfield使用
league/oauth2客户机库来实现OAuth。因此,有关如何在twinfield库中设置OAuth客户端的详细信息,请参阅league/oauth2客户端
支持一些现成的提供商,并允许第三方提供商。您的提供商可能在任何列表中。如果没有,请参阅提供商的文档以获得正确的URL。使用这种类型的OAuth2重定向流,您需要首先将用户发送到登录提供商;在他们使用凭据进行授权后,他们会被重定向回您的应用程序(到您指定的redirectUri
),并在URL中附加code
get参数。然后这些代码可以被交换成访问令牌。我不完全理解你的意思。如何将用户发送到登录提供商?这是否意味着我需要先设置一个API连接,然后再将该连接发送给提供商?如果您有一个代码示例,那将非常有帮助!(不是说你需要为我做工作xD)指的是,这基本上是你需要实现的。无论必要的URL端点是什么,您都需要通过Twinfield API文档了解。(除非你的SDk已经以硬编码的形式包含了它们。)这让我更接近了,谢谢!尽管现在我一直收到“无效授权”错误。我不完全确定为什么。。。