LoginSignup
6
4

More than 3 years have passed since last update.

[Twilio/nodejs]今だからこそ二段階認証(二要素認証)を試してみる

Last updated at Posted at 2019-07-05

とあるpayアプリで話題になってる二段階認証(二要素認証)今だからこそTwilioで試して見ようと思います。

AUTHY_API_KEYの調べ方

AUTHY_API_KEYの調べ方はこちら

新規ユーザー登録

request

curl "https://api.authy.com/protected/json/users/new" \
-H "X-Authy-API-Key: [AUTHY_API_KEY]" \
-d user[email]=your email address \
-d user[cellphone]=90xxxxxxxx \
-d user[country_code]=81
response

{
    "message": "ユーザーの作成に成功しました。",
    "user": {
        "id": <userId>
    },
    "success": true
}

ユーザー確認用SMS送信

request

curl https://api.authy.com/protected/json/sms/<userId>?force=true -H "X-Authy-API-Key: [AUTHY_API_KEY]"
response

{
    "success": true,
    "message": "SMS token was sent",
    "cellphone": "+81-XXX-XXX-XXXX"
}

ユーザー確認

request

curl https://api.authy.com/protected/json/verify/<SMSで届いた認証コード>/<userId> -H "X-Authy-API-Key: [AUTHY_API_KEY]"
response

{
    "message": "Token is valid.",
    "token": "is valid",
    "success": "true",
    "device": {
        "id": null,
        "os_type": "sms",
        "registration_date": 1562338290,
        "registration_method": null,
        "registration_country": null,
        "registration_region": null,
        "registration_city": null,
        "country": null,
        "region": null,
        "city": null,
        "ip": null,
        "last_account_recovery_at": null,
        "last_sync_date": null
    }
}

まとめ

なんと3APIで二段階認証が実装できます!
今だからこそ導入を検討してみてください。

webアプリサンプル

node.jsで書かれたサンプルをdockerで動くように改良しました!
それ使えばすぐにAuthy試せるのでお試しください!

6
4
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
6
4