logo
/
Auth0

Auto0とは

認証を担うIDaaS

フロントとバックで認証を共有する

フロント

  • UserIdTokenを取得する
    • reactならgetAccessTokenWithPopup(local)かgetAccessTokenSilently
    • Auth0Provideraudienceを指定するとJWTで取得できる
  • fetchのheaderに設定する
	fetch(userDetailsByIdUrl, {
		headers: {
				Authorization: `Bearer ${accessToken}`,
		},
	});
  • loginWithRedirectで実装するとリダイレクト後のクエリストリングにcodestateが入ってくる
    • 多分これでログインユーザーを判定して、react上のauth0と連携してると思う
    • あとからクエリを除けばOK

バック

Node.jsでユーザーの情報を取得する

  • Auth0 Management APIを使用してNode.jsでユーザーを管理してみたを参考に進める
  • Client is not authorized to access \"https://dev-jb3jt2m4.jp.auth0.com/api/v2/\". You need to create a \"client-grant\" associated to this API.....が出た
    • Auth0 Manegement API->Machine to Machine Applications
      • Autorizedを有効にする
  • Client has not been granted scopes: read:usersが出た
    • Auth0 Manegement API->Machine to Machine Applications->Ahthorizedのドロップダウンを展開して、read:usersを有効にする

ログイン画面のカスタマイズ