I want to get a real Facebook link.
So after authentication with the Omniauth Gem, I've linked like this:
https://www.facebook.com/app_scoped_user_id/960601127305294/
but my real profile link is: https://www.facebook.com/kuzevanoff
So for my system, there are two different links.
How can I solve my problem?
Thanks!
My Omniauth hash:
Started GET "/auth/facebook" for 127.0.0.1 at 2015-05-31 13:40:45 +0200
I, [2015-05-31T13:40:45.979688 #56787] INFO -- omniauth: (facebook) Request phase initiated.
<OmniAuth::AuthHash credentials=#<OmniAuth::AuthHash expires=true expires_at=1438249229 token="CAAXPwjr1V5oBABodmqtUPAGyPhnMBo3v7Q0Jifa8c7ZAYvvxYQiJoAydA1zJdeB6x9Gq8tRJFkEUeZAs003MnEe2mseO09UQwY3uvrS2JpodVqIauqRZAxUFbHBW234BB9s4q31WKpeOmbEzZBfmnP1cpowO3UWTOhfsfqFJObiPsZCKFPlZAjBH3rP6Fl6ldl62jUcLHDSIu7xubWPTvT"> extra=#<OmniAuth::AuthHash raw_info=#<OmniAuth::AuthHash email="boriska-iriska#yandex.ru" first_name="Boris" gender="male" id="960601127305294" last_name="Kuzevanov" link="https://www.facebook.com/app_scoped_user_id/960601127305294/" locale="ru_RU" name="Boris Kuzevanov" timezone=2 updated_time="2015-05-03T21:09:59+0000" verified=true>> info=#<OmniAuth::AuthHash::InfoHash email="boriska-iriska#yandex.ru" first_name="Boris" image="http://graph.facebook.com/960601127305294/picture" last_name="Kuzevanov" name="Boris Kuzevanov" urls=#<OmniAuth::AuthHash Facebook="https://www.facebook.com/app_scoped_user_id/960601127305294/"> verified=true> provider="facebook" uid="960601127305294">
If you're using omniauth-facebook gem, then you get following Auth Hash as request.env['omniauth.auth']
# Example from omniauth-facebook gem
# https://github.com/mkdynamic/omniauth-facebook#auth-hash
{
:provider => 'facebook',
:uid => '1234567',
:info => {
:nickname => 'jbloggs',
:email => 'joe#bloggs.com',
:name => 'Joe Bloggs',
:first_name => 'Joe',
:last_name => 'Bloggs',
:image => 'http://graph.facebook.com/1234567/picture?type=square',
:urls => { :Facebook => 'http://www.facebook.com/jbloggs' },
:location => 'Palo Alto, California',
:verified => true
},
# Removed non-essential part for brevity..
}
As you can see profile url is avialble via info > urls > Facebook. Also, you can just append nickname to root url to get the profile link.
"http://www.facebook.com/" + omniauth_hash.info.nickname
Related
I'm using paypal for payment and here is main function and parameters which are used for payment.
def self.paypal_url(.....)
values = {
:business => 'email#id.com',
:cmd => '_cart',
:upload => 1,
:return => return_url,
:invoice => "#{customer.id}_#{sType.id}_#{Time.now}",
:notify_url => notify_url
}
values.merge!({
"amount_1" => amount,
"item_name_1" => sType.show_title,
"discount_amount_1" => discount
# "quantity_1" => '1'
})
"https://www.paypal.com/cgi-bin/webscr?" + values.to_query
end
But now i want to use PayFlow. Kindly guide me which parameter i have to change and what will be the final url as for payment is "https://www.paypal.com/cgi-bin/webscr?" + values.to_query.
Kindly guide me?
There is a Rails example of payflow pro with hosted pages on git:
https://gist.github.com/supairish/5872581
The code gets the token to use in an iframe in your view.
You can see an example here:
https://developer.paypal.com/docs/classic/payflow/gs_ppa_hosted_pages/
I also found this resource helpful:
How do I test my integration with the Payflow Gateway using the hosted pages?
www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1493
I am working on a rails app where I need to access users Google Double Click for Publisher Data. I am using the 'google-dfp-api' gem. I have set up OmniAuth for users to authenticate their DFP accounts and am storing the refresh token per the google documentation (https://developers.google.com/doubleclick-publishers/docs/authentication). I can not figure out how to use the refresh token to access the DFP api.
I am attempting to make the connection as shown below:
dfp = DfpApi::Api.new({
:authentication => {
:method => 'OAuth2',
:oauth2_client_id => GOOGLE_CLIENT_ID,
:oauth2_client_secret => GOOGLE_CLIENT_SECRET,
:user_agent => USER_AGENT,
:application_name => APP_NAME,
:oauth2_token => {
:refresh_token => GOOGLE_DFP_REFRESH_TOKEN
}
},
:service => {
:environment => 'PRODUCTION'
}
})
AnyTime I attempt to make a query after this I get the following error:
DfpApi::V201411::UserService::ApiException: [AuthenticationError.AUTHENTICATION_FAILED # ]
You do not use the refresh token to access the api, use your access_token. I am refreshing the access_token before I make a call.
Refresh your token:
def refresh_access_token
refresh_token = self.refresh_token
google_refresh_url = "https://accounts.google.com/o/oauth2/token"
response = RestClient.post google_refresh_url, :grant_type => 'refresh_token', :refresh_token => refresh_token, :client_id => ENV['GOOGLE_CLIENT_ID'], :client_secret => ENV['GOOGLE_CLIENT_SECRET']
response_hashed = JSON.parse(response)
new_access_token = response_hashed['access_token']
self.save_new_access_token(new_access_token)
end
Then the OAuth DFP API hash should look as below:
#api = DfpApi::Api.new({
:authentication => {
:method => 'OAuth2',
:oauth2_client_id => ENV['GOOGLE_CLIENT_ID'],
:oauth2_client_secret => ENV['GOOGLE_CLIENT_SECRET'],
:application_name => ENV['GOOGLE_APP_NAME'],
:client_customer_id => google_dfp_credential.google_client_customer_id,
:network_code => google_dfp_credential.network_code,
:user_agent => ENV['GOOGLE_DFP_USER_AGENT'],
:oauth2_token => {
:access_token => google_dfp_credential.access_token,
},
},
:service => {
:environment => 'PRODUCTION'
}
})
The user_agent is a unique string to your app, that should be the same every time you access the api. See the link below for more info on that:
http://googleadsdeveloper.blogspot.com/2013/11/please-set-user-agent-or-application.html
You will also need to get the network_code from the the dfp account you are accessing by logging into the dfp account manually. To my knowledge this is not returned with OAuth authentication. See step 2 in the link below for more info on how to get the network_code:
https://developers.google.com/doubleclick-publishers/docs/start
I send this info to paypal for using preapproved payment feature:
response = gateway.preapprove_payment(
:return_url => user_orders_url(current_user),
:cancel_url => user_orders_url(current_user),
:requestEnvelope => {"errorLanguage" => "en_US"},
:start_date => Time.now,
:end_date => Time.now + (60*60*24) * 30,
:currency_code =>"USD",
:senderEmail =>"email address of sender",
:max_amount => "20.00",
:maxNumberOfPayments => "1",
:notify_url => ipn_notification_user_orders_url(current_user),
)
redirect_to (gateway.redirect_url_for(response["preapprovalKey"]))
p response
I get a message in paypal page:
This transaction is invalid. Please return to the recipient's website and try again.
I am using the method build_preapproval_payment from this gem https://github.com/jpablobr/active_paypal_adaptive_payment/blob/master/lib/active_merchant/billing/gateways/paypal_adaptive_payment.rb
This is the output in my log console:
#<ActiveMerchant::Billing::AdaptivePaymentResponse:0xb7c6838 #json="{\"responseEnvelope\":{\"timestamp\":\"2012-07-23T09:32:42.631-07:00\",\"ack\":\"Success\",\"correlationId\":\"0c4df4aefe651\",\"build\":\"DEV\"},\"preapprovalKey\":\"PA-8D4362235H161382C\"}", #response=#<Hashie::Rash preapproval_key="PA-8D4362235H161382C" response_envelope=#<Hashie::Rash ack="Success" build="DEV" correlation_id="0c4df4aefe651" timestamp="2012-07-23T09:32:42.631-07:00">>, #xml_request="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<PreapprovalRequest>\n <requestEnvelope>\n <detailLevel>ReturnAll</detailLevel>\n <errorLanguage>en_US</errorLanguage>\n <senderEmail>sender_email</senderEmail>\n </requestEnvelope>\n <endingDate>2012-08-22T18:32:40</endingDate>\n <startingDate>2012-07-23T18:32:40</startingDate>\n <maxTotalAmountOfAllPayments>20.00</maxTotalAmountOfAllPayments>\n <maxNumberOfPayments>1</maxNumberOfPayments>\n <currencyCode>USD</currencyCode>\n <cancelUrl>http://localhost:3000/en/u/maserranocaceres/orders</cancelUrl>\n <returnUrl>http://localhost:3000/en/u/maserranocaceres/orders</returnUrl>\n <ipnNotificationUrl>http://localhost:3000/en/u/maserranocaceres/orders/ipn_notification</ipnNotificationUrl>\n</PreapprovalRequest>\n", #request={"PreapprovalRequest"=>{"requestEnvelope"=>{"detailLevel"=>"ReturnAll", "errorLanguage"=>"en_US", "senderEmail"=>"microf_1342709287_biz#gmail.com"}, "endingDate"=>"2012-08-22T18:32:40", "startingDate"=>"2012-07-23T18:32:40", "maxTotalAmountOfAllPayments"=>"20.00", "maxNumberOfPayments"=>"1", "currencyCode"=>"USD", "cancelUrl"=>"http://localhost:3000/en/u/maserranocaceres/orders", "returnUrl"=>"http://localhost:3000/en/u/maserranocaceres/orders", "ipnNotificationUrl"=>"http://localhost:3000/en/u/maserranocaceres/orders/ipn_notification"}}, #action="Preapproval">
Where have I the error?
Thank you!
Well, according to my investigation of the source code of that gem the proper redirect_url method for preapproved payments is redirect_pre_approval_url_for
redirect_pre_approval_url_for(token)
I have a Rails 3 app with Omniauth and Devise. I haven't been able to find a solid tutorial showing how I should write specs for testing the functionality.
What I want to achieve is to ensure that the Sign Up and Sign In forms are working... meaning users can create accounts. I also want to be sure that the Omniauth FB Connect works as well at all times.
What/how can I write test for these scenarios above?
Thanks
The tests were very useful to test the pretty complex method I have to process authentication from Yahoo, Facebook, Google and AOL. Especially the edge cases.
This should get you started, it is the first of my 10+ scenarios.
.feature file
Feature: Signinin with third party service: Google, Aol, Facebook and Yahoo
In order to use the site
As a User
I want to sign in using my Facebook or Gmail accounts
Before do
OmniAuth.config.test_mode = true
end
After do
OmniAuth.config.test_mode = false
end
Scenario Outline: Sign with valid names and emails
Given that I have a valid "<provider>" account with email "<email>" and name "<name>"
And that I am not signed in
And I go to the sign in page
When I follow image link "<provider>"
Then I should see "You signed in using your <provider> account ("
And I should see "Welcome to Death Star"
Examples: valid name and email variations
| provider | email | name |
| Google | lukeskywaler#gmail.com | luke skywlaker |
| Facebook | darth.vader#aol.com | darth vader |
my_step.rb helper:
Given /^that I have a valid "([^"]*)" account with email "([^"]*)" and name "([^"]*)"$/ do |provider, email, name|
OmniAuth.config.test_mode = true
if provider.downcase == "yahoo" or provider.downcase == "google" or provider.downcase == "aol"
# the symbol passed to mock_auth is the same as the name of the provider set up in the initializer
OmniAuth.config.mock_auth[:open_id] =
{
'provider' => "#{provider}",
'uid' => "#{provider}.com",
'user_info' => { 'email' => "#{email}", 'name' => "#{name}"}
}
else
# the symbol passed to mock_auth is the same as the name of the provider set up in the initializer
OmniAuth.config.mock_auth[:facebook] = {
'provider' => 'facebook',
'uid' => "531564247",
'credentials' => {
'token'=> "18915faketoken22|2.NKt21XnznTNEDTTERDGYXI2UUw__.3600.1302234329200-531564247|Mi0DhWREl6g-T9bMZnL82u7s4MI"
},
'user_info' => {
'nickname' => "profile.php?id=53232564247",
'email' => "#{email}",
'first_name' => "Luke",
'last_name' => "Skywalker",
'name' => "Luke Skywalker",
'image' => "http://graph.facebook.com/5asd54247/picture?type=square",
'urls' => {
'facebook' => "http://www.facebook.com/profile.php?id=5asd54247",
'website' => ""
}
},
'extra' => {
'user_hash' => {
'id' => "5asd54247",
'name' => "#{name}",
'first_name' => "#{name.split(' ')[0]}",
'last_name' => "#{name.split(' ')[1]}",
'link' => "http://www.facebook.com/profile.php?id=5asd54247",
'birthday' => "12/7/1932",
'hometown' => {
'id' => "104048449631599",
'name' => "Menlo Park, California"
},
'location' => {
'id' => "104048449631599",
'name' => "Menlo Park, California"
},
'gender' => "male",
'email' => "#{email}",
'timezone' => "-7",
'locale' => "en_US",
'verified' => true
}
}
}
end
end
Hope this help.
I am trying to get LDAP authentication to work under Rails.
I have chosen net/ldap since it's a native Ruby LDAP library.
I have tried all possible stuff, specially examples from http://net-ldap.rubyforge.org/classes/Net/LDAP.html but still unable to get it work.
Any ideas?
The best solution I managed to reach is a Model with the following:
require 'net/ldap'
class User < ActiveRecord::Base
def after_initialize
#config = YAML.load(ERB.new(File.read("#{Rails.root}/config/ldap.yml")).result)[Rails.env]
end
def ldap_auth(user, pass)
ldap = initialize_ldap_con
result = ldap.bind_as(
:base => #config['base_dn'],
:filter => "(#{#config['attributes']['id']}=#{user})",
:password => pass
)
if result
# fetch user DN
get_user_dn user
sync_ldap_with_db user
end
nil
end
private
def initialize_ldap_con
options = { :host => #config['host'],
:port => #config['port'],
:encryption => (#config['tls'] ? :simple_tls : nil),
:auth => {
:method => :simple,
:username => #config['ldap_user'],
:password => #config['ldap_password']
}
}
Net::LDAP.new options
end
def get_user_dn(user)
ldap = initialize_ldap_con
login_filter = Net::LDAP::Filter.eq #config['attributes']['id'], "#{user}"
object_filter = Net::LDAP::Filter.eq "objectClass", "*"
ldap.search :base => #config['base_dn'],
:filter => object_filter & login_filter,
:attributes => ['dn', #config['attributes']['first_name'], #config['attributes']['last_name'], #config['attributes']['mail']] do |entry|
logger.debug "DN: #{entry.dn}"
entry.each do |attr, values|
values.each do |value|
logger.debug "#{attr} = #{value}"
end
end
end
end
end
I work on a Devise plugin for Rails 3 that uses LDAP for authentication, you can look at the source to get some ideas, it currently uses net-ldap 0.1.1:
http://github.com/cschiewek/devise_ldap_authenticatable
The actual connecting and authenticating to the LDAP sever is done at:
http://github.com/cschiewek/devise_ldap_authenticatable/blob/master/lib/devise_ldap_authenticatable/ldap_adapter.rb
Lastly, you can look at the sample LDAP server config and Rails 3 app I use to run the tests against:
App: http://github.com/cschiewek/devise_ldap_authenticatable/tree/master/test/rails_app/
Server: http://github.com/cschiewek/devise_ldap_authenticatable/tree/master/test/ldap/