Ueberauth Ecwid Strategy v0.1.1 Ueberauth.Strategy.Ecwid View Source
Provides an Ueberauth strategy for authenticating with Ecwid.
Setup
Create an application in Ecwid for you to use.
Register a new application at the ecwid developers page and get the client_id
and client_secret
.
Include the provider in your configuration for Ueberauth
config :ueberauth, Ueberauth,
providers: [
ecwid: { Ueberauth.Strategy.Ecwid, [] }
]
Then include the configuration for ecwid.
config :ueberauth, Ueberauth.Strategy.Ecwid.OAuth,
client_id: System.get_env("ECWID_API_KEY"),
client_secret: System.get_env("ECWID_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 default ‘scopes’ (permissions):
config :ueberauth, Ueberauth,
providers: [
ecwid: { Ueberauth.Strategy.Ecwid, [default_scope: "read_store_profile,read_catalog,read_orders,read_customers"] }
]
Default is “read_store_profile”
Link to this section Summary
Functions
Includes the credentials from the Ecwid response
Provides the extra params for the user
Cleans up the private area of the connection used for passing the raw Ecwid response around during the callback
Handles the initial redirect to the Ecwid authentication page
Provides the info for the user
Fetches the uid field from the Ecwid response. This defaults to the option uid_field
which in-turn defaults to store_id
Link to this section Functions
Includes the credentials from the Ecwid response.
Provides the extra params for the user.
This is one of the component functions that is used to construct the auth
struct. What you return here will be in the auth struct at the extra
key.
You would include any additional information within extra that does not fit
in either info
or credentials
Callback implementation for Ueberauth.Strategy.extra/1
.
Cleans up the private area of the connection used for passing the raw Ecwid response around during the callback.
Handles the initial redirect to the Ecwid authentication page.
To customize the scope (permissions) that are requested by ewcid include them as part of your url:
"https://my.ecwid.com/api/oauth/authorize?store_id={store_id}&scope=read_store_profile"
You can also include a state
param that ecwid will return to you.
Provides the info for the user.
This is one of the component functions that is used to construct the auth
struct. What you return here will be in the auth struct at the info
key.
Callback implementation for Ueberauth.Strategy.info/1
.
Fetches the uid field from the Ecwid response. This defaults to the option uid_field
which in-turn defaults to store_id