lib/flexmls_api/authentication/oauth2.rb in flexmls_api-0.6.5 vs lib/flexmls_api/authentication/oauth2.rb in flexmls_api-0.7.0

- old
+ new

@@ -3,18 +3,10 @@ module FlexmlsApi module Authentication - module OAuth2Impl - require 'flexmls_api/authentication/oauth2_impl/middleware' - require 'flexmls_api/authentication/oauth2_impl/grant_type_base' - require 'flexmls_api/authentication/oauth2_impl/grant_type_refresh' - require 'flexmls_api/authentication/oauth2_impl/grant_type_code' - require 'flexmls_api/authentication/oauth2_impl/grant_type_password' - end - #=OAuth2 Authentication # Auth implementation to the API using the OAuth2 service endpoint. Current adheres to the 10 # draft of the OAuth2 specification. With OAuth2, the application supplies credentials for the # application, and a separate a user authentication flow dictactes the active user for # requests. @@ -28,11 +20,11 @@ #==OAuth2 # Implementation the BaseAuth interface for API style authentication class OAuth2 < BaseAuth def initialize(client) - @client = client + super(client) @provider = client.oauth2_provider end def session @provider.load_session() @@ -118,22 +110,27 @@ # credentials will be sent to this uri to generate an access token. # @redirect_uri - Application uri to redirect to # @client_id - OAuth2 provided application identifier # @client_secret - OAuth2 provided password for the client id class BaseOAuth2Provider - - attr_accessor :authorization_uri, :access_uri, :grant_type, :client_id, :client_secret - + attr_accessor *Configuration::OAUTH2_KEYS # Requirements for authorization_code grant type - attr_accessor :code, :redirect_uri - # Requirements for password grant type - attr_accessor :username, :password + attr_accessor :code + attr_accessor :grant_type + def initialize(opts={}) + Configuration::OAUTH2_KEYS.each do |key| + send("#{key}=", opts[key]) if opts.include? key + end + @grant_type = :authorization_code + end + def grant_type - :authorization_code + # backwards compatibility check + @grant_type.nil? ? :authorization_code : @grant_type end - + # Application using the client must handle user redirect for user authentication. For # command line applications, this method is called prior to initial client requests so that # the process can notify the user to go to the url and retrieve the access_code for the app. # In a web based web application, this method can be mostly ignored. However, the web based # application is then responsible for ensuring the code is saved to the the provider instance @@ -164,8 +161,17 @@ 86400 # 1.day end end + module OAuth2Impl + require 'flexmls_api/authentication/oauth2_impl/middleware' + require 'flexmls_api/authentication/oauth2_impl/grant_type_base' + require 'flexmls_api/authentication/oauth2_impl/grant_type_refresh' + require 'flexmls_api/authentication/oauth2_impl/grant_type_code' + require 'flexmls_api/authentication/oauth2_impl/grant_type_password' + require 'flexmls_api/authentication/oauth2_impl/password_provider' + end + end end