Skip to content

Commit f13aaf9

Browse files
woyliescrogson
authored andcommitted
Spring cleaning (#138)
* add formatter config * update dialyxir to 1.0.0-rc.6 * run formatter * replace call to deprecated function * fix typos * minor grammar and formatting fixes * update deps * fix grammar * add @impl * add type specs * fix body type * improve header type * ensure proper error for malformed content-type * update type spec * add elixir 1.8 to ci config * add credo * add format check and credo to ci * update deps * set cli env for coveralls.html * improve test coverage * Revert "update deps" This reverts commit 52bafbd. * add test case for with_body option
1 parent 369cca0 commit f13aaf9

29 files changed

+595
-263
lines changed

.credo.exs

+162
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# This file contains the configuration for Credo and you are probably reading
2+
# this after creating it with `mix credo.gen.config`.
3+
#
4+
# If you find anything wrong or unclear in this file, please report an
5+
# issue on GitHub: https://github.com/rrrene/credo/issues
6+
#
7+
%{
8+
#
9+
# You can have as many configs as you like in the `configs:` field.
10+
configs: [
11+
%{
12+
#
13+
# Run any exec using `mix credo -C <name>`. If no exec name is given
14+
# "default" is used.
15+
#
16+
name: "default",
17+
#
18+
# These are the files included in the analysis:
19+
files: %{
20+
#
21+
# You can give explicit globs or simply directories.
22+
# In the latter case `**/*.{ex,exs}` will be used.
23+
#
24+
included: ["lib/", "src/", "test/", "web/", "apps/"],
25+
excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"]
26+
},
27+
#
28+
# Load and configure plugins here:
29+
#
30+
plugins: [],
31+
#
32+
# If you create your own checks, you must specify the source files for
33+
# them here, so they can be loaded by Credo before running the analysis.
34+
#
35+
requires: [],
36+
#
37+
# If you want to enforce a style guide and need a more traditional linting
38+
# experience, you can change `strict` to `true` below:
39+
#
40+
strict: true,
41+
#
42+
# If you want to use uncolored output by default, you can change `color`
43+
# to `false` below:
44+
#
45+
color: true,
46+
#
47+
# You can customize the parameters of any check by adding a second element
48+
# to the tuple.
49+
#
50+
# To disable a check put `false` as second element:
51+
#
52+
# {Credo.Check.Design.DuplicatedCode, false}
53+
#
54+
checks: [
55+
#
56+
## Consistency Checks
57+
#
58+
{Credo.Check.Consistency.ExceptionNames, []},
59+
{Credo.Check.Consistency.LineEndings, []},
60+
{Credo.Check.Consistency.ParameterPatternMatching, []},
61+
{Credo.Check.Consistency.SpaceAroundOperators, []},
62+
{Credo.Check.Consistency.SpaceInParentheses, []},
63+
{Credo.Check.Consistency.TabsOrSpaces, []},
64+
65+
#
66+
## Design Checks
67+
#
68+
# You can customize the priority of any check
69+
# Priority values are: `low, normal, high, higher`
70+
#
71+
{Credo.Check.Design.AliasUsage,
72+
[priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]},
73+
# You can also customize the exit_status of each check.
74+
# If you don't want TODO comments to cause `mix credo` to fail, just
75+
# set this value to 0 (zero).
76+
#
77+
{Credo.Check.Design.TagTODO, [exit_status: 2]},
78+
{Credo.Check.Design.TagFIXME, []},
79+
80+
#
81+
## Readability Checks
82+
#
83+
{Credo.Check.Readability.AliasOrder, []},
84+
{Credo.Check.Readability.FunctionNames, []},
85+
{Credo.Check.Readability.LargeNumbers, []},
86+
{Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 120]},
87+
{Credo.Check.Readability.ModuleAttributeNames, []},
88+
{Credo.Check.Readability.ModuleDoc, []},
89+
{Credo.Check.Readability.ModuleNames, []},
90+
{Credo.Check.Readability.ParenthesesInCondition, []},
91+
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
92+
{Credo.Check.Readability.PredicateFunctionNames, []},
93+
{Credo.Check.Readability.PreferImplicitTry, []},
94+
{Credo.Check.Readability.RedundantBlankLines, []},
95+
{Credo.Check.Readability.Semicolons, []},
96+
{Credo.Check.Readability.SpaceAfterCommas, []},
97+
{Credo.Check.Readability.StringSigils, []},
98+
{Credo.Check.Readability.TrailingBlankLine, []},
99+
{Credo.Check.Readability.TrailingWhiteSpace, []},
100+
# TODO: enable by default in Credo 1.1
101+
{Credo.Check.Readability.UnnecessaryAliasExpansion, false},
102+
{Credo.Check.Readability.VariableNames, []},
103+
104+
#
105+
## Refactoring Opportunities
106+
#
107+
{Credo.Check.Refactor.CondStatements, []},
108+
{Credo.Check.Refactor.CyclomaticComplexity, []},
109+
{Credo.Check.Refactor.FunctionArity, []},
110+
{Credo.Check.Refactor.LongQuoteBlocks, []},
111+
{Credo.Check.Refactor.MapInto, false},
112+
{Credo.Check.Refactor.MatchInCondition, []},
113+
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
114+
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
115+
{Credo.Check.Refactor.Nesting, []},
116+
{Credo.Check.Refactor.UnlessWithElse, []},
117+
{Credo.Check.Refactor.WithClauses, []},
118+
119+
#
120+
## Warnings
121+
#
122+
{Credo.Check.Warning.BoolOperationOnSameValues, []},
123+
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
124+
{Credo.Check.Warning.IExPry, []},
125+
{Credo.Check.Warning.IoInspect, []},
126+
{Credo.Check.Warning.LazyLogging, false},
127+
{Credo.Check.Warning.OperationOnSameValues, []},
128+
{Credo.Check.Warning.OperationWithConstantResult, []},
129+
{Credo.Check.Warning.RaiseInsideRescue, []},
130+
{Credo.Check.Warning.UnusedEnumOperation, []},
131+
{Credo.Check.Warning.UnusedFileOperation, []},
132+
{Credo.Check.Warning.UnusedKeywordOperation, []},
133+
{Credo.Check.Warning.UnusedListOperation, []},
134+
{Credo.Check.Warning.UnusedPathOperation, []},
135+
{Credo.Check.Warning.UnusedRegexOperation, []},
136+
{Credo.Check.Warning.UnusedStringOperation, []},
137+
{Credo.Check.Warning.UnusedTupleOperation, []},
138+
139+
#
140+
# Controversial and experimental checks (opt-in, just replace `false` with `[]`)
141+
#
142+
{Credo.Check.Consistency.MultiAliasImportRequireUse, false},
143+
{Credo.Check.Design.DuplicatedCode, false},
144+
{Credo.Check.Readability.MultiAlias, false},
145+
{Credo.Check.Readability.Specs, false},
146+
{Credo.Check.Readability.SinglePipe, false},
147+
{Credo.Check.Refactor.ABCSize, false},
148+
{Credo.Check.Refactor.AppendSingleItem, false},
149+
{Credo.Check.Refactor.DoubleBooleanNegation, false},
150+
{Credo.Check.Refactor.ModuleDependencies, false},
151+
{Credo.Check.Refactor.PipeChainStart, false},
152+
{Credo.Check.Refactor.VariableRebinding, false},
153+
{Credo.Check.Warning.MapGetUnsafePass, false},
154+
{Credo.Check.Warning.UnsafeToAtom, false}
155+
156+
#
157+
# Custom checks can be created using `mix credo.gen.check`.
158+
#
159+
]
160+
}
161+
]
162+
}

.formatter.exs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[
2+
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
3+
]

.travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ matrix:
2020
elixir: 1.6
2121
- otp_release: 21.0
2222
elixir: 1.7
23+
- otp_release: 21.0
24+
elixir: 1.8
2325

2426
env:
2527
GLOBAL:
@@ -28,4 +30,6 @@ env:
2830
sudo: false
2931

3032
after_script:
33+
- mix format --check-formatted
34+
- mix credo
3135
- mix coveralls.travis

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ for more details.
4848

4949
## Debug mode
5050

51-
Some times its handy to see what's coming back from the response when getting
51+
Sometimes it's handy to see what's coming back from the response when getting
5252
a token. You can configure OAuth2 to output the response like so:
5353

5454
```elixir

config/config.exs

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use Mix.Config
33
config :logger, level: :debug
44

55
config :oauth2,
6-
client_id: "0bee1126b1a1381d9cab60bcd52349484451808a", # first commit sha of this library
7-
client_secret: "f715d64092fe81c396ac383e97f8a7eca40e7c89", #second commit sha
6+
# first commit sha of this library
7+
client_id: "0bee1126b1a1381d9cab60bcd52349484451808a",
8+
# second commit sha
9+
client_secret: "f715d64092fe81c396ac383e97f8a7eca40e7c89",
810
redirect_uri: "http://example.com/auth/callback",
911
request_opts: []

lib/oauth2.ex

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ defmodule OAuth2 do
22
@moduledoc """
33
The OAuth2 specification
44
5-
http://tools.ietf.org/html/rfc6749
5+
[RFC6749](http://tools.ietf.org/html/rfc6749)
66
77
The OAuth 2.0 authorization framework enables a third-party
88
application to obtain limited access to an HTTP service, either on
@@ -12,13 +12,13 @@ defmodule OAuth2 do
1212
1313
## API
1414
15-
Current implemented strategies:
15+
Currently implemented strategies:
1616
1717
- Authorization Code
1818
- Password
1919
- Client Credentials
2020
21-
#### Authorization Code Flow (AuthCode Strategy)
21+
### Authorization Code Flow (AuthCode Strategy)
2222
2323
Initialize a client with your `client_id`, `client_secret`, and `site`.
2424

lib/oauth2/access_token.ex

+21-18
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@ defmodule OAuth2.AccessToken do
1414

1515
@standard ["access_token", "refresh_token", "expires_in", "token_type"]
1616

17-
@type access_token :: binary
17+
@type access_token :: binary
1818
@type refresh_token :: binary | nil
19-
@type expires_at :: integer
20-
@type token_type :: binary
21-
@type other_params :: %{binary => binary}
22-
@type body :: binary | map
19+
@type expires_at :: integer
20+
@type token_type :: binary
21+
@type other_params :: %{binary => binary}
22+
@type body :: binary | map | list
2323

2424
@type t :: %__MODULE__{
25-
access_token: access_token,
26-
refresh_token: refresh_token,
27-
expires_at: expires_at,
28-
token_type: token_type,
29-
other_params: other_params}
25+
access_token: access_token,
26+
refresh_token: refresh_token,
27+
expires_at: expires_at,
28+
token_type: token_type,
29+
other_params: other_params
30+
}
3031

3132
defstruct access_token: "",
3233
refresh_token: nil,
@@ -58,21 +59,21 @@ defmodule OAuth2.AccessToken do
5859
def new(response) when is_map(response) do
5960
{std, other} = Map.split(response, @standard)
6061

61-
struct(AccessToken, [
62-
access_token: std["access_token"],
62+
struct(AccessToken,
63+
access_token: std["access_token"],
6364
refresh_token: std["refresh_token"],
64-
expires_at: (std["expires_in"] || other["expires"]) |> expires_at,
65-
token_type: std["token_type"] |> normalize_token_type(),
66-
other_params: other
67-
])
65+
expires_at: (std["expires_in"] || other["expires"]) |> expires_at,
66+
token_type: std["token_type"] |> normalize_token_type(),
67+
other_params: other
68+
)
6869
end
6970

7071
@doc """
7172
Determines if the access token will expire or not.
7273
7374
Returns `true` unless `expires_at` is `nil`.
7475
"""
75-
@spec expires?(AccessToken.t) :: boolean
76+
@spec expires?(AccessToken.t()) :: boolean
7677
def expires?(%AccessToken{expires_at: nil} = _token), do: false
7778
def expires?(_), do: true
7879

@@ -87,12 +88,14 @@ defmodule OAuth2.AccessToken do
8788
Returns a unix timestamp based on now + expires_at (in seconds).
8889
"""
8990
def expires_at(nil), do: nil
91+
9092
def expires_at(val) when is_binary(val) do
9193
val
92-
|> Integer.parse
94+
|> Integer.parse()
9395
|> elem(0)
9496
|> expires_at
9597
end
98+
9699
def expires_at(int), do: unix_now() + int
97100

98101
defp normalize_token_type(nil), do: "Bearer"

0 commit comments

Comments
 (0)