{"id":18306401,"url":"https://github.com/xinz/ueberauth_openwechat","last_synced_at":"2025-04-09T10:49:30.573Z","repository":{"id":239943139,"uuid":"372768079","full_name":"xinz/ueberauth_openwechat","owner":"xinz","description":null,"archived":false,"fork":false,"pushed_at":"2021-06-01T09:10:22.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-04T22:49:45.476Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xinz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-01T09:09:17.000Z","updated_at":"2021-06-01T09:10:25.000Z","dependencies_parsed_at":"2024-05-16T03:17:10.754Z","dependency_job_id":"55475183-b043-4d43-bfce-efe1eb960dad","html_url":"https://github.com/xinz/ueberauth_openwechat","commit_stats":null,"previous_names":["xinz/ueberauth_openwechat"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xinz%2Fueberauth_openwechat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xinz%2Fueberauth_openwechat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xinz%2Fueberauth_openwechat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xinz%2Fueberauth_openwechat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xinz","download_url":"https://codeload.github.com/xinz/ueberauth_openwechat/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248027383,"owners_count":21035594,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T15:39:09.114Z","updated_at":"2025-04-09T10:49:30.554Z","avatar_url":"https://github.com/xinz.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# UeberauthOpenWeChat\n\n\u003e WeChat OAuth2 strategy for Überauth.\n\n## Installation\n\n1.  Setup your application at [WeChat Open Platform](https://open.weixin.qq.com/).\n\n2.  Add `:ueberauth_openwechat` to your list of dependencies in `mix.exs`.\n\n3.  Add WeChat to your Überauth configuration:\n\n     ```elixir\n     config :ueberauth, Ueberauth,\n       providers: [\n         wechat: {Ueberauth.Strategy.WeChat, []}\n       ]\n     ```\n4.  Update your provider configuration:\n\n    Use that if you want to read app ID/secret from the environment\n    variables in the compile time:\n\n    ```elixir\n    config :ueberauth, Ueberauth.Strategy.WeChat.OAuth,\n      appid: System.get_env(\"WECHAT_APP_ID\"),\n      appsecret: System.get_env(\"WECHAT_APP_SECRET\")\n    ```\n\n    Use that if you want to read app ID/secret from the environment\n    variables in the run time:\n\n    ```elixir\n    config :ueberauth, Ueberauth.Strategy.WeChat.OAuth,\n      appid: {System, :get_env, [\"WECHAT_APP_ID\"]},\n      appsecret: {System, :get_env, [\"WECHAT_APP_SECRET\"]}\n    ```\n     \n    Note: this configuration is optional if do not fetch user information in this service,\n    there provide a optional way to pass the `authorization code` to the third application,\n    and then fetch user information with the above mentioned `appid` and `appsecret` configuration.\n\n5.  Include the Überauth plug in your controller:\n\n    ```elixir\n    defmodule MyApp.AuthController do\n      use MyApp.Web, :controller\n      plug Ueberauth\n      ...\n    end\n    ```\n\n6.  Create the request and callback routes if you haven't already:\n\n    ```elixir\n    scope \"/auth\", MyApp do\n      pipe_through :browser\n\n      get \"/:provider\", AuthController, :request\n      get \"/:provider/callback\", AuthController, :callback\n    end\n    ```\n\n    Note:\n    \n    * If the defined service will pass the authorization code to the third application, the `/auth/:provider/callback`\n      url is useless.\n    * If the defined service will *ONLY* use the authorization code to fetch user information, the `/auth/:provider` url\n      is useless.\n\n7.  Your controller needs to implement callbacks to deal with `Ueberauth.Auth` and `Ueberauth.Failure` responses,\n    for example:\n\n    ```elixir\n    defmodule MyApp.AuthController do\n      use UehelloWeb, :controller\n\n      plug Ueberauth\n\n      alias Ueberauth.Strategy.Helpers\n\n      def request(conn, _params) do\n        render(conn, \"request.html\", callback_url: Helpers.callback_url(conn))\n      end\n\n      def callback(%{assigns: %{ueberauth_failure: fails}} = conn, _params) do\n        conn\n        |\u003e put_flash(:error, \"Failed to authenticate.\")\n        |\u003e redirect(to: \"/\")\n      end\n\n      def callback(%{assigns: %{ueberauth_auth: auth}} = conn, _params) do\n        IO.inspect(auth)\n        ...\n      end\n    end\n    ```\n\n## Calling\n\nDepending on the configured url you can initiate the request through:\n\n```text\n/auth/wechat\n```\n\nOr with options:\n\n```text\n/auth/wechat?appid=YOUR_APPID\n```\n\nCustom the lang parameter to call the [snsapi_userinfo](https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Before_Develop/Official_Accounts/official_account_website_authorization.html) API\n\n```text\n/auth/wechat?appid=YOUR_APPID\u0026lang=zh_CN\n```\n\nIf you want to pass the authorization code to the third application (e.g \"https://yourthirdapp.com/auth/wechat/callback\") to finish OAuth2:\n\n```text\n/auth/wechat?appid=YOUR_APPID\u0026lang=zh_CN\u0026redirect_uri=https%3A%2F%2Fyourthirdapp.com%2Fauth%2Fwechat%2Fcallback\n```\n\nIn this case, after a user authorized, we will see the authorization code parameter into like this:\n\n```text\nhttps://yourthirdapp.com/auth/wechat/callback?code=CODE\n```\n\nYou can fetch the authorized user information in the third application by the `code` and the configured `appid` and `appsecret`.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxinz%2Fueberauth_openwechat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxinz%2Fueberauth_openwechat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxinz%2Fueberauth_openwechat/lists"}