File tree 4 files changed +23
-6
lines changed
lib/songkick/oauth2/provider
spec/songkick/oauth2/provider
4 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -362,10 +362,10 @@ determine whether to serve the request or not.
362
362
363
363
It is also common to provide a dynamic resource for getting some basic data
364
364
about a user by supplying their access token. This can be done by passing
365
- <tt>nil </tt> as the resource owner:
365
+ <tt>:implicit </tt> as the resource owner:
366
366
367
367
get '/me' do
368
- token = Songkick::OAuth2::Provider.access_token(nil , [], env)
368
+ token = Songkick::OAuth2::Provider.access_token(:implicit , [], env)
369
369
if token.valid?
370
370
JSON.unparse('username' => token.owner.username)
371
371
else
Original file line number Diff line number Diff line change 105
105
# Domain API
106
106
107
107
get '/me' do
108
- authorization = Songkick ::OAuth2 ::Provider . access_token ( nil , [ ] , env )
108
+ authorization = Songkick ::OAuth2 ::Provider . access_token ( :implicit , [ ] , env )
109
109
headers authorization . response_headers
110
110
status authorization . response_status
111
111
Original file line number Diff line number Diff line change @@ -56,8 +56,13 @@ def validate!
56
56
return @error = EXPIRED_TOKEN if @authorization . expired?
57
57
return @error = INSUFFICIENT_SCOPE unless @authorization . in_scope? ( @scopes )
58
58
59
- if @resource_owner and @authorization . owner != @resource_owner
60
- @error = INSUFFICIENT_SCOPE
59
+ case @resource_owner
60
+ when :implicit
61
+ # no error
62
+ when nil
63
+ @error = INVALID_TOKEN
64
+ else
65
+ @error = INSUFFICIENT_SCOPE if @authorization . owner != @resource_owner
61
66
end
62
67
end
63
68
end
Original file line number Diff line number Diff line change 52
52
it_should_behave_like "valid token"
53
53
end
54
54
55
+ describe "with an implicit user" do
56
+ let :token do
57
+ Songkick ::OAuth2 ::Provider ::AccessToken . new ( :implicit , [ 'profile' ] , 'magic-key' )
58
+ end
59
+ it_should_behave_like "valid token"
60
+ end
61
+
55
62
describe "with no user" do
56
63
let :token do
57
64
Songkick ::OAuth2 ::Provider ::AccessToken . new ( nil , [ 'profile' ] , 'magic-key' )
58
65
end
59
- it_should_behave_like "valid token"
66
+ it_should_behave_like "invalid token"
67
+
68
+ it "returns an error response" do
69
+ token . response_headers [ 'WWW-Authenticate' ] . should == "OAuth realm='Demo App', error='invalid_token'"
70
+ token . response_status . should == 401
71
+ end
60
72
end
61
73
62
74
describe "with less scope than was granted" do
You can’t perform that action at this time.
0 commit comments