LoginSignup
2
8

More than 5 years have passed since last update.

Flaskを使用してRESTful APIを実装する(ユーザー認証編)

Last updated at Posted at 2018-09-20

はじめに

Flaskを使用してRESTful APIを実装しましたので、以下に公開しました。
https://github.com/oliverSI/flask-restful-authentication

使ったもの

  • docker
  • nginx
  • uWSGI
  • Flask
  • MongoDB
  • JSON Web Token(JWT).

準備

  1. GitHubからリポジトリをクローンします。
git clone https://github.com/oliverSI/flask-restful-authentication.git
  1. 以下のようにメールサーバーの設定をします。
export EMAIL_SERVER=[EMAIL_SERVER]
export EMAIL_USERNAME=[EMAIL_USERNAME]
export EMAIL_PASSWORD=[EMAIL_PASSWORD]
  1. 以下のコマンドでコンテナを起動します。
sudo docker-compose up -d

使用方法

登録

curl -X POST -H "Content-Type: application/json" -d '{"email": "test@example.com", "password": "password"}' http://127.0.0.1/v1/register

アクティベーション

curl -X PUT -H "Content-Type: application/json" -d '{"activation_code": "activation code you received"}’ http://127.0.0.1/v1/activate

ログイン

curl -X GET -H "Content-Type: application/json" -d '{"email": “test@example.com", "password": "password"}’ http://127.0.0.1/v1/login

ログイン後の操作

curl -H "Authorization: Bearer [token you got]" -H "Content-Type: application/json" http://127.0.0.1/v1/todo
2
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
8