View Source WeChat.Plug.OAuth2Checker (wechat v0.13.6)

网页授权

官方文档

工作流程:

  1. 检查 session, 判断是否已经有授权,有则继续执行后续的 plug, 没有则跳到步骤 2;
  2. 检查 query 是否有 code, 有则执行 oauth2_callback_fun 函数, 没有则跳到步骤 3;
  3. 执行 authorize_url_fun 函数,跳转到 authorize_url.

可选参数:

注意 : 服务器角色为 hub_client 时,请确保已经配置 hub_springboard_url:

WeChat.HubClient.set_hub_springboard_url(Client, "https://wx.example.com")

Usage

将下面的代码加到 router 里面:

pipeline :oauth2_checker do
  plug WeChat.Plug.OAuth2Checker, clients: [Client, ...]
end

# for normal
scope "/:app" do
  pipe_through :oauth2_checker
  get "/path", YourController, :your_action
end

# for work
scope "/:app/:agent" do
  pipe_through :oauth2_checker
  # 在PC端授权访问网页
  get "/:qr/your_path", YourController, :your_action
  # 在企业微信内授权访问网页
  get "/your_path", YourController, :your_action
end

Summary

Types

获取授权链接函数

授权回调处理函数

Types

@type authorize_url_fun() ::
  (:normal
   | :work
   | :work_qr,
   Plug.Conn.t(),
   WeChat.client(),
   WeChat.Work.Agent.t() ->
     authorize_url :: String.t())

获取授权链接函数

@type oauth2_callback_fun() ::
  (:normal
   | :work,
   Plug.Conn.t(),
   WeChat.WebPage.code(),
   WeChat.client(),
   WeChat.Work.Agent.t() ->
     Plug.Conn.t())

授权回调处理函数

Functions

Link to this function

auth_success(conn, client, info)

View Source
Link to this function

auth_success(conn, client, agent, info)

View Source
Link to this function

authorize_url_by_server_role(type, conn, client, agent)

View Source
Link to this function

check_code(conn, options, type, client, agent)

View Source
Link to this function

hub_springboard_callback_uri(conn, hub_springboard_url)

View Source
Link to this function

oauth2_callback(atom, conn, code, client, agent)

View Source