Skip to content

Commit f77bd76

Browse files
authored
Merge pull request #47 from clupprich/master
Add Github Actions for CI, cont'd
2 parents 009aeb1 + a36a33d commit f77bd76

File tree

9 files changed

+133
-39
lines changed

9 files changed

+133
-39
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @ueberauth/developers

.github/workflows/ci.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
3+
name: Continuous Integration
4+
5+
on:
6+
pull_request:
7+
types:
8+
- opened
9+
- reopened
10+
- synchronize
11+
12+
jobs:
13+
Test:
14+
runs-on: ubuntu-latest
15+
16+
container:
17+
image: elixir:1.11-alpine
18+
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v2
22+
with:
23+
persist-credentials: false
24+
25+
- name: Install (mix)
26+
run: |
27+
mix local.rebar --force
28+
mix local.hex --force
29+
30+
- name: Install (deps)
31+
run: mix deps.get
32+
33+
- name: Run Tests
34+
run: mix test
35+
36+
Format:
37+
runs-on: ubuntu-latest
38+
39+
container:
40+
image: elixir:1.11-alpine
41+
42+
steps:
43+
- name: Checkout Code
44+
uses: actions/checkout@v2
45+
with:
46+
persist-credentials: false
47+
48+
- name: Install (mix)
49+
run: |
50+
mix local.rebar --force
51+
mix local.hex --force
52+
mix deps.get
53+
54+
- name: Run Formatter
55+
run: mix format --check-formatted
56+
57+
Credo:
58+
runs-on: ubuntu-latest
59+
60+
container:
61+
image: elixir:1.11-alpine
62+
63+
steps:
64+
- name: Checkout Code
65+
uses: actions/checkout@v2
66+
with:
67+
persist-credentials: false
68+
69+
- name: Install (os)
70+
run: apk add --no-cache gcc g++ git make musl-dev tar zstd
71+
72+
- name: Install (mix)
73+
run: |
74+
mix local.rebar --force
75+
mix local.hex --force
76+
77+
- name: Install (deps)
78+
run: mix deps.get
79+
80+
- name: Run Credo
81+
run: mix credo

config/test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

lib/ueberauth/strategy/twitter.ex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ defmodule Ueberauth.Strategy.Twitter do
55

66
use Ueberauth.Strategy, uid_field: :id_str
77

8-
alias Ueberauth.Auth.Info
98
alias Ueberauth.Auth.Credentials
109
alias Ueberauth.Auth.Extra
11-
alias Ueberauth.Strategy.Twitter
10+
alias Ueberauth.Auth.Info
11+
alias Ueberauth.Strategy.Twitter.OAuth
1212

1313
@doc """
1414
Handles initial request for Twitter authentication.
1515
"""
1616
def handle_request!(conn) do
1717
params = with_state_param([], conn)
18-
token = Twitter.OAuth.request_token!([], redirect_uri: callback_url(conn, params))
18+
token = OAuth.request_token!([], redirect_uri: callback_url(conn, params))
1919

2020
conn
2121
|> put_session(:twitter_token, token)
22-
|> redirect!(Twitter.OAuth.authorize_url!(token))
22+
|> redirect!(OAuth.authorize_url!(token))
2323
end
2424

2525
@doc """
@@ -28,7 +28,7 @@ defmodule Ueberauth.Strategy.Twitter do
2828
def handle_callback!(%Plug.Conn{params: %{"oauth_verifier" => oauth_verifier}} = conn) do
2929
token = get_session(conn, :twitter_token)
3030

31-
case Twitter.OAuth.access_token(token, oauth_verifier) do
31+
case OAuth.access_token(token, oauth_verifier) do
3232
{:ok, access_token} -> fetch_user(conn, access_token)
3333
{:error, error} -> set_errors!(conn, [error(error.code, error.reason)])
3434
end
@@ -104,7 +104,7 @@ defmodule Ueberauth.Strategy.Twitter do
104104
defp fetch_user(conn, token) do
105105
params = [{"include_entities", false}, {"skip_status", true}, {"include_email", true}]
106106

107-
case Twitter.OAuth.get("/1.1/account/verify_credentials.json", params, token) do
107+
case OAuth.get("/1.1/account/verify_credentials.json", params, token) do
108108
{:ok, %{status_code: 401, body: _, headers: _}} ->
109109
set_errors!(conn, [error("token", "unauthorized")])
110110

lib/ueberauth/strategy/twitter/internal.ex

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@ defmodule Ueberauth.Strategy.Twitter.OAuth.Internal do
44
"""
55

66
def get(url, extraparams, {consumer_key, consumer_secret, _}, token \\ "", token_secret \\ "") do
7-
creds = OAuther.credentials(
8-
consumer_key: consumer_key,
9-
consumer_secret: consumer_secret,
10-
token: token,
11-
token_secret: token_secret
12-
)
7+
creds =
8+
OAuther.credentials(
9+
consumer_key: consumer_key,
10+
consumer_secret: consumer_secret,
11+
token: token,
12+
token_secret: token_secret
13+
)
14+
1315
{header, params} =
1416
"get"
1517
|> OAuther.sign(url, extraparams, creds)
16-
|> OAuther.header
18+
|> OAuther.header()
19+
20+
response = HTTPoison.get(url, [header, {"Accept", "application/json"}], params: params)
1721

18-
HTTPoison.get(url, [header, {"Accept", "application/json"}], params: params)
22+
response
1923
|> decode_body()
2024
end
2125

@@ -40,12 +44,7 @@ defmodule Ueberauth.Strategy.Twitter.OAuth.Internal do
4044
def decode_body(other), do: other
4145

4246
def params_decode(resp) do
43-
resp
44-
|> String.split("&", trim: true)
45-
|> Enum.map(&String.split(&1, "="))
46-
|> Enum.map(&List.to_tuple/1)
47-
|> Enum.into(%{})
48-
# |> Enum.reduce(%{}, fn({name, val}, acc) -> Map.put_new(acc, name, val) end)
47+
URI.decode_query(resp)
4948
end
5049

5150
def token(params) do

lib/ueberauth/strategy/twitter/oauth.ex

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ defmodule Ueberauth.Strategy.Twitter.OAuth do
1212

1313
alias Ueberauth.Strategy.Twitter.OAuth.Internal
1414

15-
@defaults [access_token: "/oauth/access_token",
16-
authorize_url: "/oauth/authorize",
17-
request_token: "/oauth/request_token",
18-
site: "https://api.twitter.com"]
15+
@defaults [
16+
access_token: "/oauth/access_token",
17+
authorize_url: "/oauth/authorize",
18+
request_token: "/oauth/request_token",
19+
site: "https://api.twitter.com"
20+
]
1921

2022
defmodule ApiError do
2123
@moduledoc "Raised on OAuth API errors."
2224

2325
defexception [:message, :code]
2426

25-
def message(e = %{code: nil}), do: e.message
27+
def message(%{code: nil} = e), do: e.message
2628

2729
def message(e) do
2830
"#{e.message} (Code #{e.code})"
@@ -60,6 +62,7 @@ defmodule Ueberauth.Strategy.Twitter.OAuth do
6062
end
6163

6264
def get(url, access_token), do: get(url, [], access_token)
65+
6366
def get(url, params, {token, token_secret}) do
6467
client()
6568
|> to_url(url)
@@ -93,6 +96,10 @@ defmodule Ueberauth.Strategy.Twitter.OAuth do
9396
{:ok, {token, token_secret}}
9497
end
9598

99+
defp decode_response({:ok, %{status_code: 401, body: body}}) do
100+
{:error, "401: #{inspect(body)}"}
101+
end
102+
96103
defp decode_response({:ok, %{body: %{"errors" => [error | _]}}}) do
97104
{:error, %ApiError{message: error["message"], code: error["code"]}}
98105
end

mix.exs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ defmodule UeberauthTwitter.Mixfile do
88
[
99
app: :ueberauth_twitter,
1010
version: @version,
11-
name: "Überauth Twitter",
11+
name: "Ueberauth Twitter Strategy",
12+
package: package(),
1213
elixir: "~> 1.1",
1314
build_embedded: Mix.env() == :prod,
1415
start_permanent: Mix.env() == :prod,
15-
package: package(),
16+
source_url: @source_url,
17+
homepage_url: @source_url,
1618
deps: deps(),
1719
docs: docs()
1820
]
@@ -29,7 +31,8 @@ defmodule UeberauthTwitter.Mixfile do
2931
{:ueberauth, "~> 0.7"},
3032

3133
# dev/test dependencies
32-
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false},
34+
{:earmark, ">= 0.0.0", only: :dev},
35+
{:ex_doc, "~> 0.18", only: :dev},
3336
{:credo, "~> 0.8", only: [:dev, :test]}
3437
]
3538
end

mix.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
%{
22
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"},
3-
"certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "805abd97539caf89ec6d4732c91e62ba9da0cda51ac462380bbd28ee697a8c42"},
3+
"certifi": {:hex, :certifi, "2.6.1", "dbab8e5e155a0763eea978c913ca280a6b544bfa115633fa20249c3d396d9493", [:rebar3], [], "hexpm", "524c97b4991b3849dd5c17a631223896272c6b0af446778ba4675a1dff53bb7e"},
44
"credo": {:hex, :credo, "0.10.2", "03ad3a1eff79a16664ed42fc2975b5e5d0ce243d69318060c626c34720a49512", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "539596b6774069260d5938aa73042a2f5157e1c0215aa35f5a53d83889546d14"},
55
"earmark": {:hex, :earmark, "1.3.1", "73812f447f7a42358d3ba79283cfa3075a7580a3a2ed457616d6517ac3738cb9", [:mix], [], "hexpm", "000aaeff08919e95e7aea13e4af7b2b9734577b3e6a7c50ee31ee88cab6ec4fb"},
66
"earmark_parser": {:hex, :earmark_parser, "1.4.13", "0c98163e7d04a15feb62000e1a891489feb29f3d10cb57d4f845c405852bbef8", [:mix], [], "hexpm", "d602c26af3a0af43d2f2645613f65841657ad6efc9f0e361c3b6c06b578214ba"},
77
"ex_doc": {:hex, :ex_doc, "0.24.2", "e4c26603830c1a2286dae45f4412a4d1980e1e89dc779fcd0181ed1d5a05c8d9", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "e134e1d9e821b8d9e4244687fb2ace58d479b67b282de5158333b0d57c6fb7da"},
8-
"hackney": {:hex, :hackney, "1.15.1", "9f8f471c844b8ce395f7b6d8398139e26ddca9ebc171a8b91342ee15a19963f4", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.4", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "c2790c9f0f7205f4a362512192dee8179097394400e745e4d20bab7226a8eaad"},
8+
"hackney": {:hex, :hackney, "1.17.4", "99da4674592504d3fb0cfef0db84c3ba02b4508bae2dff8c0108baa0d6e0977c", [:rebar3], [{:certifi, "~>2.6.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "de16ff4996556c8548d512f4dbe22dd58a587bf3332e7fd362430a7ef3986b16"},
99
"httpoison": {:hex, :httpoison, "1.5.0", "71ae9f304bdf7f00e9cd1823f275c955bdfc68282bc5eb5c85c3a9ade865d68e", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "e9d994aea63fab9e29307920492ab95f87339b56fbc5c8c4b1f65ea20d3ba9a4"},
10-
"idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "4bdd305eb64e18b0273864920695cb18d7a2021f31a11b9c5fbcd9a253f936e2"},
10+
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
1111
"jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fdf843bca858203ae1de16da2ee206f53416bbda5dc8c9e78f43243de4bc3afe"},
1212
"makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"},
1313
"makeup_elixir": {:hex, :makeup_elixir, "0.15.1", "b5888c880d17d1cc3e598f05cdb5b5a91b7b17ac4eaf5f297cb697663a1094dd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "db68c173234b07ab2a07f645a5acdc117b9f99d69ebf521821d89690ae6c6ec8"},
@@ -17,11 +17,11 @@
1717
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
1818
"nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"},
1919
"oauther": {:hex, :oauther, "1.1.1", "7d8b16167bb587ecbcddd3f8792beb9ec3e7b65c1f8ebd86b8dd25318d535752", [:mix], [], "hexpm", "9374f4302045321874cccdc57eb975893643bd69c3b22bf1312dab5f06e5788e"},
20-
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm", "17ef63abde837ad30680ea7f857dd9e7ced9476cdd7b0394432af4bfc241b960"},
20+
"parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},
2121
"plug": {:hex, :plug, "1.11.1", "f2992bac66fdae679453c9e86134a4201f6f43a687d8ff1cd1b2862d53c80259", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "23524e4fefbb587c11f0833b3910bfb414bf2e2534d61928e920f54e3a1b881f"},
2222
"plug_crypto": {:hex, :plug_crypto, "1.2.2", "05654514ac717ff3a1843204b424477d9e60c143406aa94daf2274fdd280794d", [:mix], [], "hexpm", "87631c7ad914a5a445f0a3809f99b079113ae4ed4b867348dd9eec288cecb6db"},
23-
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.4", "f0eafff810d2041e93f915ef59899c923f4568f4585904d010387ed74988e77b", [:make, :mix, :rebar3], [], "hexpm", "603561dc0fd62f4f2ea9b890f4e20e1a0d388746d6e20557cafb1b16950de88c"},
23+
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},
2424
"telemetry": {:hex, :telemetry, "0.4.3", "a06428a514bdbc63293cd9a6263aad00ddeb66f608163bdec7c8995784080818", [:rebar3], [], "hexpm", "eb72b8365ffda5bed68a620d1da88525e326cb82a75ee61354fc24b844768041"},
2525
"ueberauth": {:hex, :ueberauth, "0.7.0", "9c44f41798b5fa27f872561b6f7d2bb0f10f03fdd22b90f454232d7b087f4b75", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "2efad9022e949834f16cc52cd935165049d81fa9e925690f91035c2e4b58d905"},
26-
"unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm", "1d1848c40487cdb0b30e8ed975e34e025860c02e419cb615d255849f3427439d"},
26+
"unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},
2727
}

test/strategy/twitter/oauth_test.exs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,35 @@ defmodule Ueberauth.Strategy.Twitter.OAuthTest do
44
alias Ueberauth.Strategy.Twitter.OAuth
55

66
setup do
7-
Application.put_env :ueberauth, OAuth,
7+
Application.put_env(:ueberauth, OAuth,
88
consumer_key: "consumer_key",
99
consumer_secret: "consumer_secret"
10+
)
11+
1012
:ok
1113
end
1214

1315
test "access_token!/2: raises an appropriate error on auth failure" do
1416
assert_raise RuntimeError, ~r/401/i, fn ->
15-
OAuth.access_token! {"badtoken", "badsecret"}, "badverifier"
17+
OAuth.access_token!({"badtoken", "badsecret"}, "badverifier")
1618
end
1719
end
1820

1921
test "access_token!/2 raises an appropriate error on network failure" do
2022
assert_raise RuntimeError, ~r/nxdomain/i, fn ->
21-
OAuth.access_token! {"token", "secret"}, "verifier", site: "https://bogusapi.twitter.com"
23+
OAuth.access_token!({"token", "secret"}, "verifier", site: "https://bogusapi.twitter.com")
2224
end
2325
end
2426

2527
test "request_token!/2: raises an appropriate error on auth failure" do
2628
assert_raise RuntimeError, ~r/401/i, fn ->
27-
OAuth.request_token! [], redirect_uri: "some/uri"
29+
OAuth.request_token!([], redirect_uri: "some/uri")
2830
end
2931
end
3032

3133
test "request_token!/2: raises an appropriate error on network failure" do
3234
assert_raise RuntimeError, ~r/nxdomain/i, fn ->
33-
OAuth.request_token! [], site: "https://bogusapi.twitter.com", redirect_uri: "some/uri"
35+
OAuth.request_token!([], site: "https://bogusapi.twitter.com", redirect_uri: "some/uri")
3436
end
3537
end
3638
end

0 commit comments

Comments
 (0)