View Source Ueberauth.Strategy.Tiktok (ueberauth_tiktok v0.1.0)
Provides an Überauth strategy for authenticating with Tiktok
Setup
Create an application in Tiktok for you to use.
Register a new application at: tiktok developer page
and get the client_key
and client_secret
.
Include the provider in your configuration for Ueberauth;
config :ueberauth, Ueberauth,
providers: [
tiktok: { Ueberauth.Strategy.Tiktok, [] }
]
Then include the configuration for Tiktok:
config :ueberauth, Ueberauth.Strategy.Tiktok.OAuth,
client_key: System.get_env("TIKTOK_CLIENT_KEY"),
client_secret: System.get_env("TIKTOK_CLIENT_SECRET")
If you haven't already, create a pipeline and setup routes for your callback handler
pipeline :auth do
Ueberauth.plug "/auth"
end
scope "/auth" do
pipe_through [:browser, :auth]
get "/:provider/callback", AuthController, :callback
end
Create an endpoint for the callback where you will handle the
Ueberauth.Auth
struct:
defmodule MyApp.AuthController do
use MyApp.Web, :controller
def callback_phase(%{ assigns: %{ ueberauth_failure: fails } } = conn, _params) do
# do things with the failure
end
def callback_phase(%{ assigns: %{ ueberauth_auth: auth } } = conn, params) do
# do things with the auth
end
end
You can edit the behaviour of the Strategy by including some options when you register your provider.
To set the redirect_uri
:
config :ueberauth, Ueberauth,
providers: [
tiktok: { Ueberauth.Strategy.Tiktok, [redirect_uri: "https://redirect-uri-example.com/auth/tiktok/callback"] }
]
To set the default 'scopes' (permissions):
config :ueberauth, Ueberauth,
providers: [
tiktok: { Ueberauth.Strategy.Tiktok, [default_scope: "user.basic.info"] }
]
Default is user.basic.info which "Grants read-only access to some user profile information."
Summary
Functions
Includes the credentials from the Tiktok response.
Callback implementation for Ueberauth.Strategy.default_options/0
.
Stores the raw information (including the token) obtained from the Tiktok callback.
Cleans up the private area of the connection used for passing the raw Tiktok response around during the callback.
Handles the initial redirect to the tiktok authentication page.
Fetches the fields to populate the info section of the Ueberauth.Auth
struct.
Callback implementation for Ueberauth.Strategy.uid/1
.
Functions
Includes the credentials from the Tiktok response.
Callback implementation for Ueberauth.Strategy.default_options/0
.
Stores the raw information (including the token) obtained from the Tiktok callback.
Cleans up the private area of the connection used for passing the raw Tiktok response around during the callback.
Handles the initial redirect to the tiktok authentication page.
To customize the scope that are requested by tiktok include them as part of your url:
"/auth/tiktok?scope=user.basic.info&code_verifier=[]"
Fetches the fields to populate the info section of the Ueberauth.Auth
struct.
Callback implementation for Ueberauth.Strategy.uid/1
.