Skip to content

Instantly share code, notes, and snippets.

@kenfdev
Last active October 26, 2021 00:22
Show Gist options
  • Save kenfdev/9810eee0bf8f3bbc61d034260c71c9ac to your computer and use it in GitHub Desktop.
Save kenfdev/9810eee0bf8f3bbc61d034260c71c9ac to your computer and use it in GitHub Desktop.
Auth0

Auth0でユーザー名でのログインを可能にする

Created: 2021-08-31 18:02

Image

Requires Usernameをオンにする

Disable Signupもつけとく Image

Dashboardからusernameを変更することはできない。

APIを通さないといけない

https://auth0.com/docs/api/management/v2#!/Users/patch_users_by_id

API Token作る Image

GET Userした結果

{
  "created_at": "2021-08-31T08:22:37.230Z",
  "email": "hoge@kenfdev.test",
  "email_verified": false,
  "identities": [
    {
      "user_id": "612de6cdfb5f5e006880183d",
      "provider": "auth0",
      "connection": "Username-Password-Authentication",
      "isSocial": false
    }
  ],
  "name": "hoge@kenfdev",
  "nickname": "hoge",
  "picture": "https://s.gravatar.com/avatar/3386ef05d7c08db4b5eb7c21660dddba?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fho.png",
  "updated_at": "2021-08-31T09:07:01.854Z",
  "user_id": "auth0|612de6cdfb5f5e006880183d",
  "last_password_reset": "2021-08-31T09:04:14.352Z",
  "last_ip": "240d:1e:254:9500:d6f:f94d:ef94:2516",
  "last_login": "2021-08-31T09:07:01.854Z",
  "logins_count": 1
}

↓にリクエスト

https://kenfdev.jp.auth0.com/api/v2/users/auth0%7C612de6cdfb5f5e006880183d

リクエストボディ

{
	"username": "hoge@kenfdev"
}
{
  "created_at": "2021-08-31T08:22:37.230Z",
  "email": "hoge@kenfdev.test",
  "email_verified": false,
  "identities": [
    {
      "user_id": "612de6cdfb5f5e006880183d",
      "provider": "auth0",
      "connection": "Username-Password-Authentication",
      "isSocial": false
    }
  ],
  "name": "hoge@kenfdev",
  "nickname": "hoge",
  "picture": "https://s.gravatar.com/avatar/3386ef05d7c08db4b5eb7c21660dddba?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fho.png",
  "updated_at": "2021-08-31T11:53:48.728Z",
  "user_id": "auth0|612de6cdfb5f5e006880183d",
  "last_password_reset": "2021-08-31T09:04:14.352Z",
  "username": "hoge@kenfdev",
  "last_ip": "240d:1e:254:9500:d6f:f94d:ef94:2516",
  "last_login": "2021-08-31T09:07:01.854Z",
  "logins_count": 1
}

Custom Login Formでごにょごにょカスタマイズする Image

Reference

  1. https://auth0.com/docs/connections/database/require-username
  2. https://community.auth0.com/t/how-to-edit-nickname/39435
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment