Skip to content

Commit

Permalink
Showing 2 changed files with 18 additions and 10 deletions.
10 changes: 10 additions & 0 deletions spec/std/oauth2/access_token_spec.cr
Original file line number Diff line number Diff line change
@@ -67,6 +67,16 @@ class OAuth2::AccessToken
}))
token.extra.not_nil!["unknown"].should eq("[1,2,3]")
end

it "builds from json without token_type, assumes Bearer (#4503)" do
token = AccessToken.from_json(%({
"access_token" : "foo",
"refresh_token" : "bar",
"scope" : "baz"
}))
token.should be_a(AccessToken::Bearer)
token.access_token.should eq("foo")
end
end

describe Mac do
18 changes: 8 additions & 10 deletions src/oauth2/access_token/access_token.cr
Original file line number Diff line number Diff line change
@@ -29,17 +29,15 @@ abstract class OAuth2::AccessToken

access_token = access_token.not_nil!

if token_type
case token_type.downcase
when "bearer"
Bearer.new(access_token, expires_in, refresh_token, scope, extra)
when "mac"
Mac.new(access_token, expires_in, mac_algorithm.not_nil!, mac_key.not_nil!, refresh_token, scope, Time.now.epoch, extra)
else
raise "Uknown token_type in access token json: #{token_type}"
end
token_type ||= "bearer"

case token_type.downcase
when "bearer"
Bearer.new(access_token, expires_in, refresh_token, scope, extra)
when "mac"
Mac.new(access_token, expires_in, mac_algorithm.not_nil!, mac_key.not_nil!, refresh_token, scope, Time.now.epoch, extra)
else
raise "Missing token_type in access token json"
raise "Uknown token_type in access token json: #{token_type}"

This comment has been minimized.

Copy link
@Sija

Sija Jun 3, 2017

Contributor

Uknown -> Unknown

end
end

0 comments on commit a3b77d3

Please sign in to comment.