This page looks best with JavaScript enabled

OAuth 2 Authorization Code Grant Flow

 ·  ☕ 1 min read  ·  🎅 [emacle] · 👀... views
  • 转自 OAuth 2.0 筆記 (4.1) Authorization Code Grant Flow 細節

    在 Authorization Grant Code Flow 裡,Client 不直接向 Resource Owner 要求許可,而是把 Resource Owner 導去
    Authorization Server 要求許可, Authorization Server 再透過轉址來告訴 Client 授權許可的代碼 (code) 。
    在轉址回去之前, Authorization Server 會先認證 Resource Owner 並取得授權。因為 Resource Owner 只跟
    Authorization Server 認證,所以 Client 絕對不會拿到 Resource Owner 的帳號密碼。

註: (A), (B), (C) 這三步的線拆成兩段,因為會經過 user-agent
其 Client 指自己的应用程序(包括前端及后端api) User-Agent 一般指流览器

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

emacle
WRITTEN BY
[emacle]
Emacser orgmode

 

What's on this Page