diff --git a/lib/doorkeeper/request/authorization_code.rb b/lib/doorkeeper/request/authorization_code.rb index 092e2e9d3..9b5d74eec 100644 --- a/lib/doorkeeper/request/authorization_code.rb +++ b/lib/doorkeeper/request/authorization_code.rb @@ -1,19 +1,18 @@ +require 'doorkeeper/request/strategy' + module Doorkeeper module Request - class AuthorizationCode - attr_accessor :grant, :client, :server + class AuthorizationCode < Strategy + attr_accessor :grant, :client def initialize(server) - @grant, @client, @server = server.grant, server.client, server + super + @grant, @client = server.grant, server.client end def request @request ||= OAuth::AuthorizationCodeRequest.new(Doorkeeper.configuration, grant, client, server.parameters) end - - def authorize - request.authorize - end end end end diff --git a/lib/doorkeeper/request/client_credentials.rb b/lib/doorkeeper/request/client_credentials.rb index 8e46810cb..e65b3467e 100644 --- a/lib/doorkeeper/request/client_credentials.rb +++ b/lib/doorkeeper/request/client_credentials.rb @@ -1,19 +1,18 @@ +require 'doorkeeper/request/strategy' + module Doorkeeper module Request - class ClientCredentials - attr_accessor :client, :server + class ClientCredentials < Strategy + attr_accessor :client def initialize(server) - @client, @server = server.client, server + super + @client = server.client end def request @request ||= OAuth::ClientCredentialsRequest.new(Doorkeeper.configuration, client, server.parameters) end - - def authorize - request.authorize - end end end end diff --git a/lib/doorkeeper/request/code.rb b/lib/doorkeeper/request/code.rb index 6fea02b58..c3e045c6e 100644 --- a/lib/doorkeeper/request/code.rb +++ b/lib/doorkeeper/request/code.rb @@ -1,20 +1,18 @@ +require 'doorkeeper/request/strategy' + module Doorkeeper module Request - class Code - attr_accessor :pre_auth, :server + class Code < Strategy + attr_accessor :pre_auth def initialize(server) + super @pre_auth = server.context.send(:pre_auth) - @server = server end def request @request ||= OAuth::CodeRequest.new(pre_auth, server.current_resource_owner) end - - def authorize - request.authorize - end end end end diff --git a/lib/doorkeeper/request/password.rb b/lib/doorkeeper/request/password.rb index 26d5aa166..977eb0fa3 100644 --- a/lib/doorkeeper/request/password.rb +++ b/lib/doorkeeper/request/password.rb @@ -1,21 +1,19 @@ +require 'doorkeeper/request/strategy' + module Doorkeeper module Request - class Password - attr_accessor :credentials, :resource_owner, :server + class Password < Strategy + attr_accessor :credentials, :resource_owner def initialize(server) + super @credentials = server.credentials @resource_owner = server.resource_owner - @server = server end def request @request ||= OAuth::PasswordAccessTokenRequest.new(Doorkeeper.configuration, credentials, resource_owner, server.parameters) end - - def authorize - request.authorize - end end end end diff --git a/lib/doorkeeper/request/refresh_token.rb b/lib/doorkeeper/request/refresh_token.rb index d85be9366..159b45d34 100644 --- a/lib/doorkeeper/request/refresh_token.rb +++ b/lib/doorkeeper/request/refresh_token.rb @@ -1,21 +1,19 @@ +require 'doorkeeper/request/strategy' + module Doorkeeper module Request - class RefreshToken - attr_accessor :refresh_token, :credentials, :server + class RefreshToken < Strategy + attr_accessor :refresh_token, :credentials def initialize(server) + super @refresh_token = server.current_refresh_token @credentials = server.credentials - @server = server end def request @request ||= OAuth::RefreshTokenRequest.new(Doorkeeper.configuration, refresh_token, credentials, server.parameters) end - - def authorize - request.authorize - end end end end diff --git a/lib/doorkeeper/request/strategy.rb b/lib/doorkeeper/request/strategy.rb new file mode 100644 index 000000000..a1fd13551 --- /dev/null +++ b/lib/doorkeeper/request/strategy.rb @@ -0,0 +1,19 @@ +module Doorkeeper + module Request + class Strategy + attr_accessor :server + + def initialize(server) + self.server = server + end + + def request + raise NotImplementedError, "request strategies must define #request" + end + + def authorize + request.authorize + end + end + end +end diff --git a/lib/doorkeeper/request/token.rb b/lib/doorkeeper/request/token.rb index b938d2174..55e398d44 100644 --- a/lib/doorkeeper/request/token.rb +++ b/lib/doorkeeper/request/token.rb @@ -1,20 +1,18 @@ +require 'doorkeeper/request/strategy' + module Doorkeeper module Request - class Token - attr_accessor :pre_auth, :server + class Token < Strategy + attr_accessor :pre_auth def initialize(server) + super @pre_auth = server.context.send(:pre_auth) - @server = server end def request @request ||= OAuth::TokenRequest.new(pre_auth, server.current_resource_owner) end - - def authorize - request.authorize - end end end end