DEV Community

garicchi
garicchi

Posted on

ReactNativeでauth0を使う時にaudienceパラメータを付与する

通常のauth0 react sdkでは、audienceパラメータは以下のように注入することができるが

<Auth0Provider
        authorizationParams={{
          redirect_uri: window.location.origin,
          audience: Config.Auth0.audience,
          scope: "read:current_user"
        }}
      >
Enter fullscreen mode Exit fullscreen mode

react nativeのauth0sdkではaudienceパラメータを、Auth0Providerでは付与できない

<Auth0Provider
      domain={Config.Auth0.domain}
      clientId={Config.Auth0.clientId}
    >
Enter fullscreen mode Exit fullscreen mode

このまま使うと、例えばAspdotnetのAPIサーバーに通信したときに以下のようにキー複合化エラーが出る。
これはaudienceパラメータが無いかららしい

IDX10609: Decryption failed. No Keys tried: toke n:
Enter fullscreen mode Exit fullscreen mode

ではどうするかというと、ログイン時(authorize)にaudienceを渡すことができる

<Button onPress={async () => await authorize({
                    audience: Config.Auth0.audience
                })} title='login' />
Enter fullscreen mode Exit fullscreen mode

この認証情報をつかって発行されたaccessTokenはaudienceパラメータが付与されている

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay