我目前正在尝试设置Twinfield API,在使用php-twinfield/twinfield库时应该非常简单。但有一件事我并不完全理解。
下面是我的代码:
$provider = new OAuthProvider([
'clientId' => 'someClientId',
'clientSecret' => 'someClientSecret',
'redirectUri' => 'https://example.org/'
]);
$accessToken = $provider->getAccessToken("authorization_code", ["code" => ...]);
$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']]);这将返回'invalid_grant‘。我已尝试重置我的clientSecret...但这并没有帮助。我希望有人能进一步帮助我。
发布于 2021-05-06 17:08:15
要访问Twinfield API,必须对用户进行身份验证。您可以通过指定用户名和密码或使用OAuth2来执行此操作。在使用OAuth2时,您将身份验证委托给所谓的OAuth提供者。在用户通过身份验证后,提供程序会将用户的浏览器重定向到应用程序中的端点(redirectUri)。您的应用程序接收的那个请求有一个名为code的GET参数。然后,您的应用程序将使用其clientId、clientSecret和HTTP POST将代码交换为令牌。这意味着您的应用程序必须在OAuth2提供商处注册,以便提供商(例如github、facebook、google等)可以验证客户端凭据并返回令牌。并且,您必须配置provider变量以指向您连接的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-client库来实现OAuth。因此,有关如何在twinfield库中设置OAuth客户端的详细信息,请参阅https://oauth2-client.thephpleague.com/usage/。league/oauth2-client支持一些开箱即用的提供商,并允许第三方提供商。您的提供商可能在任何列表中。如果没有,请参考提供商的文档以获取正确的URL。
https://stackoverflow.com/questions/67413285
复制相似问题