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

JWT発行API #462

Closed
wants to merge 10 commits into from
Closed

JWT発行API #462

wants to merge 10 commits into from

Conversation

ras0q
Copy link
Member

@ras0q ras0q commented Sep 24, 2023

close #422

knoQをブラウザを介さずに(BOT,他appなどから)アクセスしたい需要があったのでトークンを発行するAPIを書きました
そもそもJWTじゃないほうがいいとかあれば教えていただけるとありがたいです

@ras0q
Copy link
Member Author

ras0q commented Sep 24, 2023

UIがないのでknoQの開発環境開いてOAuth2認証をした上で

await (await fetch('/api/token', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  }
})).json()

をしてtokenを発行します
シークレットウィンドウを開いて

await (await fetch('/api/events', {
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer {ここにトークン}'
  }
})).json()

をするとOAuth2認証なしでイベントが取れると思います

@ras0q ras0q requested review from iChemy and Luftalian September 24, 2023 12:47
router/authorization.go Outdated Show resolved Hide resolved
router/authorization.go Show resolved Hide resolved
Comment on lines +97 to +100
ErrorHandler: func(c echo.Context, err error) error {
return nil
},
ContinueOnIgnoredError: true,
Copy link
Member Author

Choose a reason for hiding this comment

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

これがないとJWTないとき弾かれるんだけどこれを追加していいのか自信がない

Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/traPtitech/knoQ/pull/462/files#diff-c399d26e7f23b713ce01946ac9e0e6f1fc94d692e8a086180191901da91b6964R61

単純にここの順番を入れ替えてしまうという手段がある(隠された実装に依存するけどたぶん配列回してるだけ)

Copy link
Member Author

Choose a reason for hiding this comment

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

先に部員認証しちゃうとIDが入ってなくてトークン使えなさそう

@ras0q ras0q changed the title JWTtoken発行API JWT発行API Sep 24, 2023
@@ -80,6 +82,30 @@ func ServerVersionMiddleware(version string) echo.MiddlewareFunc {
}
}

func (h *Handlers) JWTMiddleware() echo.MiddlewareFunc {
return echojwt.WithConfig(
echojwt.Config{
Copy link
Member

Choose a reason for hiding this comment

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

Signing Methodは明示的に書いたほうがいい(デフォルト値だとわからないので)

Comment on lines +97 to +100
ErrorHandler: func(c echo.Context, err error) error {
return nil
},
ContinueOnIgnoredError: true,
Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/traPtitech/knoQ/pull/462/files#diff-c399d26e7f23b713ce01946ac9e0e6f1fc94d692e8a086180191901da91b6964R61

単純にここの順番を入れ替えてしまうという手段がある(隠された実装に依存するけどたぶん配列回してるだけ)

@ras0q ras0q requested a review from hijiki51 October 25, 2023 13:34
@ras0q
Copy link
Member Author

ras0q commented Oct 26, 2023

別の手段で最低でも30日くらいは使えるトークンにする

@itt828
Copy link
Member

itt828 commented Jun 10, 2024

@ras0q

別の手段で最低でも30日くらいは使えるトークンにする

kwsk(このPRの実装だとうまく行かない理由教えてほしいです:pray:)

@ras0q
Copy link
Member Author

ras0q commented Jun 21, 2024

JWTで30日は長すぎるみたいな指摘が入ったからですね

@ras0q
Copy link
Member Author

ras0q commented Jun 28, 2024

多分これはマージされないのでクローズ

@ras0q ras0q closed this Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

アクセストークンの発行
3 participants