wechat_mp_auth v0.0.2 WechatMPAuth.Client

This module defines the WechatMPAuth.Client struct and is responsible for building and establishing a request for an component access token.

Summary

Functions

Get authorize url to get authorized

Returns an WechatMPAuth.AuthorizerAccessToken struct that can then be used to access the authorizer’s RESTful API.

Arguments

Returns an WechatMPAuth.ComponentAccessToken struct that can then be used to access the provider’s RESTful API.

Arguments

  • client - a WechatMPAuth.Client struct with the strategy to use
  • params - a keyword list of request parameters

Set multiple params in the client in one call

Builds a new WechatMPAuth client struct using the opts provided.

Client struct fields

  • strategy - a module that implements the Wechat MP Auth strategy, defaults to WechatMPAuth.Strategy.AuthCode
  • client_id - the client_id for the Wechat Component
  • client_secret - the client_secret for the Wechat Component
  • site - the WechatMPAuth provider site host
  • authorize_url - absolute or relative URL path to the token endpoint. Defaults to "https://mp.weixin.qq.com/cgi-bin/componentloginpage"
  • authorizer_access_token_url - absolute or relative URL path to the authorizer’s authorization endpoint. Defaults to "/component/api_query_auth"
  • component_access_token_url - absolute or relative URL path to the component’s authorization endpoint. Defaults to "/component/api_component_token"
  • pre_auth_code_url - absolute or relative URL path to the authentication code endpoint. Defaults to "/component/api_create_preauthcode"
  • params - a map of request parameters
  • redirect_uri - the URI the provider should redirect to after authorization or token requests

Puts the specified value in the params for the given key. The key can be a string or an atom. Atoms are automatically convert to strings

Types

authorize_url :: binary
client_id :: binary
client_secret :: binary
param :: binary | %{binary => param} | [param]
params :: %{binary => param}
pre_auth_code_url :: binary
redirect_uri :: binary
site :: binary
strategy :: module
t :: %WechatMPAuth.Client{authorize_url: authorize_url, authorizer_access_token_url: authorizer_access_token_url, client_id: client_id, client_secret: client_secret, component_access_token_url: component_access_token_url, params: params, pre_auth_code_url: pre_auth_code_url, redirect_uri: redirect_uri, site: site, strategy: strategy}

Functions

get_authorize_url(client, params \\ [])

Specs

get_authorize_url(t, list) :: {t, binary}

Get authorize url to get authorized.

get_authorizer_access_token(client, params)

Specs

get_authorizer_access_token(t, params) ::
  {:ok, AuthoerizerAccessToken.t} |
  {:error, Error.t}

Returns an WechatMPAuth.AuthorizerAccessToken struct that can then be used to access the authorizer’s RESTful API.

Arguments

get_component_access_token(client, params \\ [])

Specs

get_component_access_token(t, params) ::
  {:ok, WechatMPAuth.ComponentAccessToken.t} |
  {:error, Error.t}

Returns an WechatMPAuth.ComponentAccessToken struct that can then be used to access the provider’s RESTful API.

Arguments

  • client - a WechatMPAuth.Client struct with the strategy to use
  • params - a keyword list of request parameters
get_component_access_token!(client, params \\ [])

Specs

get_component_access_token!(t, params) ::
  WechatMPAuth.ComponentAccessToken.t |
  Error.t

Same as get_component_access_token/2 but raises WechatMPAuth.Error if an error occurs during the request.

merge_params(client, params)

Specs

merge_params(t, WechatMPAuth.params) :: t

Set multiple params in the client in one call.

new(opts)

Specs

new(Keyword.t) :: t

Builds a new WechatMPAuth client struct using the opts provided.

Client struct fields

  • strategy - a module that implements the Wechat MP Auth strategy, defaults to WechatMPAuth.Strategy.AuthCode
  • client_id - the client_id for the Wechat Component
  • client_secret - the client_secret for the Wechat Component
  • site - the WechatMPAuth provider site host
  • authorize_url - absolute or relative URL path to the token endpoint. Defaults to "https://mp.weixin.qq.com/cgi-bin/componentloginpage"
  • authorizer_access_token_url - absolute or relative URL path to the authorizer’s authorization endpoint. Defaults to "/component/api_query_auth"
  • component_access_token_url - absolute or relative URL path to the component’s authorization endpoint. Defaults to "/component/api_component_token"
  • pre_auth_code_url - absolute or relative URL path to the authentication code endpoint. Defaults to "/component/api_create_preauthcode"
  • params - a map of request parameters
  • redirect_uri - the URI the provider should redirect to after authorization or token requests
put_param(client, key, value)

Specs

put_param(t, String.t | atom, any) :: t

Puts the specified value in the params for the given key. The key can be a string or an atom. Atoms are automatically convert to strings.