Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Feature/add auth module #2

Draft
wants to merge 15 commits into
base: feature/add-db-migrations
Choose a base branch
from

Conversation

hayato24s
Copy link
Contributor

auth moduleを追加しました。

このモジュールでは主に下記のことを行なっています。

  • 認証・認可
  • セッションの管理
  • OAuth2に関する処理

@hayato24s hayato24s self-assigned this Sep 19, 2023
api/oauth2/handler.go Outdated Show resolved Hide resolved
api/oauth2/handler.go Outdated Show resolved Hide resolved
api/oauth2/handler.go Show resolved Hide resolved
Value: session.ID.String(),
Path: "/",
Expires: session.ExpiredAt,
HttpOnly: true,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

少なくとも本番環境では Secure をつけるようにしてほしいです。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

環境変数から指定できるように修正します。

queryState := r.URL.Query().Get("state")

if cookieState == "" || queryState == "" || cookieState != queryState {
http.Error(w, err.Error(), http.StatusInternalServerError)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これ err が nil で panic するような気がします。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

panicしますね。修正します。

case "google":
provider = authentity.ProviderGoogle
default:
http.Error(w, "invalid provider", http.StatusInternalServerError)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internal Server Error ではなさそう。
ここ以外も同じように見直したほうが良いように思います。

Comment on lines 22 to 27
if err == nil {
return next(ctx, req)
}

sessionID, err := idtype.NewSessionIDFromString(cookie.Value)
if err == nil {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

逆じゃないですか?

Suggested change
if err == nil {
return next(ctx, req)
}
sessionID, err := idtype.NewSessionIDFromString(cookie.Value)
if err == nil {
if err != nil {
return next(ctx, req)
}
sessionID, err := idtype.NewSessionIDFromString(cookie.Value)
if err != nil {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

逆ですね。修正します。

"google.golang.org/api/option"
)

//go:embed google_client_credentials.json

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これビルド時に差し込む形になっちゃうのでやめてください。
client_id と client_secret を環境変数でもらうような形にしてください。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

了解です。

}

func (h *Handler) HandleLogout(w http.ResponseWriter, r *http.Request) {
user, err := h.authUseCase.AuthorizeAuthenticatedUser(r.Context())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここでこれって動くんですか? Connect でしか処理してない気がする。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

動かないですね。別途middlewareを定義しようと思います。

@hayato24s
Copy link
Contributor Author

hayato24s commented Sep 21, 2023

@takonomura @HosokawaR

お二人ともレビューありがとうございます!
レビューを受けて修正を行ったので確認お願いします🙇‍♂️

TODO

  • エラー発生時にhttps://app.twinte.net/errorなどのエラーページに画面を遷移させたい
  • loggerを導入する

Copy link
Member

@HosokawaR HosokawaR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

お疲れ様です!ありがとうございます!

@hayato24s hayato24s marked this pull request as draft February 9, 2024 16:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants