(D) 步 客户端向 authorization server 发送 auth_code 时(手工封装时) 未带有redirect_uri貌似也能成功最好还是按标准带上该参数?
使用 oauth2-client 包时应该是封装好的 authorization_code 与 前面定义的 redirect_uri 一同发向 authorization server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php// composer require league/oauth2-client
$provider=new\League\OAuth2\Client\Provider\GenericProvider(['clientId'=>$client_id,// The client ID assigned to you by the provider
'clientSecret'=>$client_secret,// The client password assigned to you by the provider
'redirectUri'=>'http://localhost:9527/auth-redirect','urlAuthorize'=>'https://github.com/login/oauth/authorize','urlAccessToken'=>'https://github.com/login/oauth/access_token','urlResourceOwnerDetails'=>'https://api.github.com/user']);// getAccessToken 时应该带有 redirect_uri?
// http://localhost:9527/auth-redirect?code=8789d613d1fa9a19732a&state=xyz
$accessToken=$provider->getAccessToken('authorization_code',['code'=>$code]);