View Source Überauth Tiktok

Last Updated

Tiktok OAuth2 strategy for Überauth.

Installation

  1. Setup your application with Tiktok Developer Account.

  2. Add :ueberauth_tiktok to your list of dependencies in mix.exs:

    def deps do
      [
        {:ueberauth_tiktok, "~> 0.1.0"}
      ]
    end
  3. Add Tiktok to your Überauth configuration:

    config :ueberauth, Ueberauth,
      providers: [
        tiktok: {Ueberauth.Strategy.Tiktok, []}
      ]
  4. Update your provider configuration:

    config :ueberauth, Ueberauth.Strategy.Tiktok.OAuth,
      client_key: System.get_env("TIKTOK_CLIENT_KEY"),
      client_secret: System.get_env("TIKTOK_CLIENT_SECRET")

    Or, to read the client credentials at runtime:

    config :ueberauth, Ueberauth.Strategy.Tiktok.OAuth,
      client_key: {:system, "TIKTOK_CLIENT_KEY"},
      client_secret: {:system, "TIKTOK_CLIENT_SECRET"}
  5. Include the Überauth plug in your router:

    defmodule MyApp.Router do
      use MyApp.Web, :router
    
      pipeline :browser do
        plug Ueberauth
        ...
       end
    end
  6. Create the request and callback routes if you haven't already:

    scope "/auth", MyApp do
      pipe_through :browser
    
      get "/:provider", AuthController, :request
      get "/:provider/callback", AuthController, :callback
    end
  7. Your controller needs to implement callbacks to deal with Ueberauth.Auth and Ueberauth.Failure responses.

For an example implementation see the Überauth Example application.

Calling

Depending on the configured url you can initiate the request through:

/auth/tiktok

Or with options:

/auth/tiktok?scope=user.basic.info&code_verifier=

By default the requested scope is "user.basic.info". This provides read access to the Tiktok user profile details. Tiktok API excludes user's email address which results in a nil for email inside returned %Ueberauth.Auth.Info{}.

See more at Tiktok's OAuth Documentation.

Scope can be configured either explicitly as a scope query value on the request path or in your configuration:

config :ueberauth, Ueberauth,
  providers: [
    github: {Ueberauth.Strategy.Tiktok, [default_scope: "user.basic.info,user.basic.profile"]}
  ]

Copyright (c) 2024 Shapath Neupane

This library is released under the MIT License. See the LICENSE.md file

Docs

Published at HexDocs.

Notes

  1. The TikTok API does not allow redirect URIs with port numbers in the staging environment. For more information, see this Stack Overflow answer.
  2. Use TIKTOK_CLIENT_KEY instead of TIKTOK_CLIENT_ID as TikTok's OAuth implementation provides a client key.