Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OAuth] Token Endpoint の作成 #28

Closed
a01sa01to opened this issue Nov 1, 2024 · 0 comments · Fixed by #42
Closed

[OAuth] Token Endpoint の作成 #28

a01sa01to opened this issue Nov 1, 2024 · 0 comments · Fixed by #42
Assignees
Labels
❇️ 新機能 新規機能の開発 優先度: 高 優先度が高いタスク 難易度: 2 初心者にとってはやりがいのあるタスク 難易度: 3 経験者向けのタスク

Comments

@a01sa01to
Copy link
Member

a01sa01to commented Nov 1, 2024

Authorization Endpoint で認可した後、リソース所有者は認可サーバ (Authorization Server) から「認可しました~」という証である Authorization Grant を受け取り、認可したサービス (Client) に渡しに行きます。
その証を受け取ると、サービスは認可サーバとやり取りをして、リソース所有者の情報を取得するための "鍵" (Token) を取得します。
その Token を取得するためのエンドポイントが、 Token Endpoint と呼ばれるものです。


エンドポイントの場所・許可するメソッド

  • パス: /oauth/access-token
  • POST メソッドを許可し、それ以外は拒否する (405 Method not allowed を返す)

受け取るパラメータ

  • client_id: Required
  • client_secret: Required
  • grant_type: Required
  • code: Required
  • redirect_uri: Optional

すべて String です

チェックすること

上から順に行うことを想定しています

  • Authorization ヘッダが含まれている場合
    • 401 Unauthorized を返す
    • WWW-Authenticate ヘッダを含め、その値は使わせたい Authorization ヘッダの値に適応させる
  • redirect_uri 以外のすべてのパラメータが存在し、かつ複数存在しないことを確認する
    • 変なら { "error": "invalid_request" } と JSON を返す。 Status は 400
  • code のレコードにおいて redirect_uri が存在するか確認する
    • null かつパラメータに redirect_uri が存在する場合は { "error": "invalid_request" } [400]
    • non-null かつパラメータの redirect_uri と一致しない場合は { "error": "invalid_request" } [400]
  • client_id, client_secret のペアが存在するか確認する
    • 存在しないなら { "error": "invalid_client" } [401]
  • grant_typeauthorization_code か確認する
    • そうでなければ { "error": "unsupported_grant_type" } [401]
  • code のレコードにおいて code_used が false か確認する
    • true だったら { "error": "invalid_grant" } [401] を返し、そのレコードを削除する
  • code のレコードにおいて code_expiration が現在時刻より後か確認する
    • そうでなければ { "error": "invalid_grant" } [401] を返し、レコードを削除する

ヘッダには Cache-Control: no-store, Pragma: no-cache を指定する

応答

以下の JSON を返す

{
  "access_token": code のレコードに格納されている access_token,
  "token_type": "bearer",
  "expires_in": token_expiration までの残り時間 (単位は秒)
  "scope": token_scope についている scope name の配列
}

ヘッダには Cache-Control: no-store, Pragma: no-cache を指定する

@a01sa01to a01sa01to added ❇️ 新機能 新規機能の開発 優先度: 高 優先度が高いタスク 難易度: 2 初心者にとってはやりがいのあるタスク 難易度: 3 経験者向けのタスク labels Nov 1, 2024
@a01sa01to a01sa01to changed the title [WIP] [OAuth Backend] Token Endpoint の作成 [WIP] [OAuth] Token Endpoint の作成 Nov 1, 2024
@a01sa01to a01sa01to self-assigned this Nov 3, 2024
@a01sa01to a01sa01to changed the title [WIP] [OAuth] Token Endpoint の作成 [OAuth] Token Endpoint の作成 Nov 8, 2024
@a01sa01to a01sa01to linked a pull request Nov 13, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❇️ 新機能 新規機能の開発 優先度: 高 優先度が高いタスク 難易度: 2 初心者にとってはやりがいのあるタスク 難易度: 3 経験者向けのタスク
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant