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

Creating an API key validator #80

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Sawawa42
Copy link
Member

This PR is to resolve #63

  • Authorizationヘッダに記載されたAPIキーと、.envのAPIキーを照合して検証するミドルウェアの作成

Warning

このブランチのマージを行った場合、M5sticks側などでもAuthorizationヘッダを使用する必要があるため、コードの変更が必要になります。

@Sawawa42
Copy link
Member Author

callback.htmlの<script>タグ内で、/receive-uidにPOSTしているので、この箇所でAuthorizationヘッダを使う必要がある。

@Sawawa42
Copy link
Member Author

  • html内に<script>タグを使ってPOSTしようとすると、このPOSTはクライアント側で実行されるのでAPIキーを渡すことができない。そのため、/callbackにアクセスされたとき、クエリパラメータuidとcodeを解析して/receive-uidにPOSTし、その結果によってhtmlの一部表記が変わるようにしたhtmlを返却するように変更した。
  • ginのGroup機能を使ってAPIキーを検証するミドルウェアの影響範囲を変更し、/や/callbackを使用するときのAPIキーを不要とした。

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.

Authenticate a request with API key
1 participant