Packages

Steam API and Auth (with Phoenix/Plug integration) for Elixir

Current section

8 Versions

Jump to

Compare versions

9 files changed
+163 additions
-158 deletions
  @@ -1,12 +1,9 @@
1 - [![Build Status](https://travis-ci.org/antipax/steamex.svg?branch=master)](https://travis-ci.org/antipax/steamex)
1 + [![Build Status](https://travis-ci.org/ericentin/steamex.svg?branch=master)](https://travis-ci.org/ericentin/steamex)
2 2
3 3 Steamex
4 4 =======
5 5
6 - Steamex is a library for interacting with Steam Auth and other APIs.
7 -
8 - Currently it only supports Steam Auth, but support for other APIs is coming
9 - soon.
6 + Steamex is a library for interacting with Steam Auth/Profiles.
10 7
11 8 If you are a Phoenix user, please look at the documentation for
12 9 `Steamex.Auth.Phoenix` for a quick-start guide.
  @@ -4,26 +4,30 @@
4 4 <<"Steam API and Auth (with Phoenix/Plug integration) for Elixir">>}.
5 5 {<<"elixir">>,<<"~> 1.0">>}.
6 6 {<<"files">>,
7 - [<<"lib/steamex.ex">>,<<"lib/steamex/auth.ex">>,
7 + [<<"lib">>,<<"lib/steamex">>,<<"lib/steamex.ex">>,<<"lib/steamex/auth">>,
8 + <<"lib/steamex/auth.ex">>,<<"lib/steamex/auth/phoenix">>,
8 9 <<"lib/steamex/auth/phoenix.ex">>,<<"lib/steamex/auth/phoenix/router.ex">>,
9 10 <<"lib/steamex/auth/phoenix/view.ex">>,<<"lib/steamex/auth/plug.ex">>,
10 11 <<"lib/steamex/profile.ex">>,<<"lib/steamex/steam_id.ex">>,<<"mix.exs">>,
11 12 <<"README.md">>,<<"LICENSE">>]}.
12 13 {<<"licenses">>,[<<"Apache 2.0">>]}.
13 - {<<"links">>,[{<<"GitHub">>,<<"https://github.com/antipax/steamex">>}]}.
14 + {<<"links">>,[{<<"GitHub">>,<<"https://github.com/ericentin/steamex">>}]}.
14 15 {<<"maintainers">>,[<<"Eric Entin">>]}.
15 16 {<<"name">>,<<"steamex">>}.
16 17 {<<"requirements">>,
17 - [[{<<"app">>,<<"httpoison">>},
18 - {<<"name">>,<<"httpoison">>},
19 - {<<"optional">>,false},
20 - {<<"requirement">>,<<"~> 0.11">>}],
21 - [{<<"app">>,<<"sweet_xml">>},
18 + [[{<<"app">>,<<"sweet_xml">>},
22 19 {<<"name">>,<<"sweet_xml">>},
23 20 {<<"optional">>,false},
21 + {<<"repository">>,<<"hexpm">>},
24 22 {<<"requirement">>,<<"~> 0.6">>}],
23 + [{<<"app">>,<<"httpoison">>},
24 + {<<"name">>,<<"httpoison">>},
25 + {<<"optional">>,false},
26 + {<<"repository">>,<<"hexpm">>},
27 + {<<"requirement">>,<<"~> 1.1">>}],
25 28 [{<<"app">>,<<"plug">>},
26 29 {<<"name">>,<<"plug">>},
27 30 {<<"optional">>,true},
31 + {<<"repository">>,<<"hexpm">>},
28 32 {<<"requirement">>,<<"~> 1.3">>}]]}.
29 - {<<"version">>,<<"0.0.7">>}.
33 + {<<"version">>,<<"0.0.9">>}.
  @@ -14,16 +14,18 @@ defmodule Steamex.Auth do
14 14 If you use `Steamex.Auth.Phoenix`, this is `realm <> "/steamex/return_to"`
15 15 by default.
16 16 """
17 - @spec auth_url(String.t, String.t) :: String.t
17 + @spec auth_url(String.t(), String.t()) :: String.t()
18 18 def auth_url(realm, return_to) when is_binary(realm) and is_binary(return_to) do
19 - @steam_login_url_base <> "?" <> URI.encode_query %{
20 - "openid.claimed_id" => "http://specs.openid.net/auth/2.0/identifier_select",
21 - "openid.identity" => "http://specs.openid.net/auth/2.0/identifier_select",
22 - "openid.mode" => "checkid_setup",
23 - "openid.ns" => "http://specs.openid.net/auth/2.0",
24 - "openid.realm" => realm,
25 - "openid.return_to" => return_to
26 - }
19 + @steam_login_url_base <>
20 + "?" <>
21 + URI.encode_query(%{
22 + "openid.claimed_id" => "http://specs.openid.net/auth/2.0/identifier_select",
23 + "openid.identity" => "http://specs.openid.net/auth/2.0/identifier_select",
24 + "openid.mode" => "checkid_setup",
25 + "openid.ns" => "http://specs.openid.net/auth/2.0",
26 + "openid.realm" => realm,
27 + "openid.return_to" => return_to
28 + })
27 29 end
28 30
29 31 @doc """
  @@ -54,15 +56,15 @@ defmodule Steamex.Auth do
54 56 Application.ensure_all_started(:httpoison)
55 57
56 58 %HTTPoison.Response{status_code: 200, body: body} =
57 - httpoison.post! @steam_login_url_base, URI.encode_query(params), [
59 + httpoison.post!(@steam_login_url_base, URI.encode_query(params), [
58 60 {"Content-Type", "application/x-www-form-urlencoded"}
59 - ]
61 + ])
60 62
61 - unless String.contains? body, "is_valid:true" do
62 - raise "Invalid auth attempt: #{inspect payload}"
63 + unless String.contains?(body, "is_valid:true") do
64 + raise "Invalid auth attempt: #{inspect(payload)}"
63 65 end
64 66
65 - "http://steamcommunity.com/openid/id/" <> steamid64_str = payload["openid.identity"]
67 + "https://steamcommunity.com/openid/id/" <> steamid64_str = payload["openid.identity"]
66 68
67 69 {steamid64, ""} = Integer.parse(steamid64_str)
  @@ -21,12 +21,16 @@ defmodule Steamex.Auth.Phoenix.Router do
21 21 add your own view helper that calls the Steamex one with the appropriate
22 22 options.
23 23 """
24 - @spec steamex_route_auth(String.t, Keyword.t, Keyword.t) :: Macro.t
25 - defmacro steamex_route_auth(url \\ "/steamex/return_to", steamex_auth_plug_opts \\ [], router_opts \\ []) do
24 + @spec steamex_route_auth(String.t(), Keyword.t(), Keyword.t()) :: Macro.t()
25 + defmacro steamex_route_auth(
26 + url \\ "/steamex/return_to",
27 + steamex_auth_plug_opts \\ [],
28 + router_opts \\ []
29 + ) do
26 30 router_opts = Keyword.merge([as: :steamex_auth_return_to], router_opts)
27 31
28 32 quote do
29 - get unquote(url), Steamex.Auth.Plug, unquote(steamex_auth_plug_opts), unquote(router_opts)
33 + get(unquote(url), Steamex.Auth.Plug, unquote(steamex_auth_plug_opts), unquote(router_opts))
30 34 end
31 35 end
32 36 end
  @@ -16,7 +16,7 @@ defmodule Steamex.Auth.Phoenix.View do
16 16 `:return_to_helper`. If you have used the default options
17 17 for `steamex_route_auth`, you do not need to set this option.
18 18 """
19 - @spec steamex_auth_url(Plug.Conn.t, Keyword.t) :: String.t
19 + @spec steamex_auth_url(Plug.Conn.t(), Keyword.t()) :: String.t()
20 20 def steamex_auth_url(conn, options \\ []) do
21 21 steamex_auth_url(conn, options, Phoenix.Controller)
22 22 end
Loading more files…