Module: AuthlogicOauth2::ActsAsAuthentic::Methods

Includes:
Oauth2Process
Defined in:
lib/authlogic_oauth2/acts_as_authentic.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

Set up some simple validations



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/authlogic_oauth2/acts_as_authentic.rb', line 30

def self.included(klass)
  klass.class_eval do
    alias_method "#{oauth2_token_field.to_s}=".to_sym, :oauth2_token=
  end

  return if !klass.column_names.include?(klass.oauth2_token_field.to_s)

  klass.class_eval do
    validate :validate_by_oauth2, :if => :authenticating_with_oauth2?

    validates_uniqueness_of klass.oauth2_token_field, :message => rw_config(:duplicate_oauth2_token_message, nil), :scope => validations_scope, :if => :using_oauth2?

    validates_length_of_password_field_options validates_length_of_password_field_options.merge(:if => :validate_password_with_oauth2?)
    validates_confirmation_of_password_field_options validates_confirmation_of_password_field_options.merge(:if => :validate_password_with_oauth2?)
    validates_length_of_password_confirmation_field_options validates_length_of_password_confirmation_field_options.merge(:if => :validate_password_with_oauth2?)
     .merge(:if => :validate_password_with_oauth2?)
     .merge(:if => :validate_password_with_oauth2?)
  end

  # email needs to be optional for oauth2
  klass.validate_email_field = false
end

Instance Method Details

#oauth2_accessObject

Provides access to an API exposed on the access_token object



76
77
78
# File 'lib/authlogic_oauth2/acts_as_authentic.rb', line 76

def oauth2_access
  access_token
end

#oauth2_tokenObject

Accessors for oauth2 fields



67
68
69
# File 'lib/authlogic_oauth2/acts_as_authentic.rb', line 67

def oauth2_token
  read_attribute(oauth2_token_field)
end

#oauth2_token=(value) ⇒ Object



71
72
73
# File 'lib/authlogic_oauth2/acts_as_authentic.rb', line 71

def oauth2_token=(value)
  write_attribute(oauth2_token_field, value.blank? ? nil : value)
end

#save(perform_validation = true) {|result| ... } ⇒ Object

Yields:

  • (result)


53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/authlogic_oauth2/acts_as_authentic.rb', line 53

def save(perform_validation = true, &block)
  if perform_validation && block_given? && redirecting_to_oauth2_server?
    # Save attributes so they aren't lost during the authentication with the oauth2 server
    session_class.controller.session[:authlogic_oauth2_attributes] = attributes.reject!{|k, v| v.blank?}
    redirect_to_oauth2
    return false
  end

  result = super
  yield(result) if block_given?
  result
end