View Source Überauth Tiktok
Tiktok OAuth2 strategy for Überauth.
Installation
Setup your application with Tiktok Developer Account.
Add
:ueberauth_tiktokto your list of dependencies inmix.exs:def deps do [ {:ueberauth_tiktok, "~> 0.1.0"} ] endAdd Tiktok to your Überauth configuration:
config :ueberauth, Ueberauth, providers: [ tiktok: {Ueberauth.Strategy.Tiktok, []} ]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"}Include the Überauth plug in your router:
defmodule MyApp.Router do use MyApp.Web, :router pipeline :browser do plug Ueberauth ... end endCreate 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 endYour controller needs to implement callbacks to deal with
Ueberauth.AuthandUeberauth.Failureresponses.
For an example implementation see the Überauth Example application.
Calling
Depending on the configured url you can initiate the request through:
/auth/tiktokOr 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 and License
Copyright (c) 2024 Shapath Neupane
This library is released under the MIT License. See the LICENSE.md file
Docs
Published at HexDocs.
Notes
- The TikTok API does not allow redirect URIs with port numbers in the staging environment. For more information, see this Stack Overflow answer.
- Use
TIKTOK_CLIENT_KEYinstead ofTIKTOK_CLIENT_IDas TikTok's OAuth implementation provides a client key.