Ueberauth Weibo v0.0.2 Ueberauth.Strategy.Weibo

Provides an Ueberauth strategy for authenticating with Weibo.

Setup

Create an application in Weib for you to use.

Register a new application at: weibo open platform page and get the client_id and client_secret.

Include the provider in your configuration for Ueberauth

config :ueberauth, Ueberauth,
  providers: [
    weibo: { Ueberauth.Strategy.Weibo, [] }
  ]

Then include the configuration for weibo.

config :ueberauth, Ueberauth.Strategy.Weibo.OAuth,
  client_id: System.get_env("WEIBO_CLIENT_ID"),
  client_secret: System.get_env("WEIBO_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

Summary

Functions

Includes the credentials from the Weibo response

Stores the raw information (including the token) obtained from the Weibo callback

Cleans up the private area of the connection used for passing the raw Weibo response around during the callback

Handles the initial redirect to the weibo authentication page

Fetches the fields to populate the info section of the Ueberauth.Auth struct

Fetches the uid field from the Weibo response

Functions

auth(conn)
credentials(conn)

Includes the credentials from the Weibo response.

default_options()
extra(conn)

Stores the raw information (including the token) obtained from the Weibo callback.

handle_cleanup!(conn)

Cleans up the private area of the connection used for passing the raw Weibo response around during the callback.

handle_request!(conn)

Handles the initial redirect to the weibo authentication page.

request url:

"/auth/weibo"

You can also include a state param that weibo will return to you.

info(conn)

Fetches the fields to populate the info section of the Ueberauth.Auth struct.

uid(conn)

Fetches the uid field from the Weibo response.