sending params using post in rails to an external application - ruby-on-rails

I am very new to ruby on rails. In my rails app, when the user logs in, I need to redirect him along with some info related to the user to an external application( a https url which ends in .action) using POST. Since redirection is a GET request, can somebody give me some pointers?

You can send a POST requests to an external application easily using the HTTParty gem

Related

LinkedIn OAuth 2.0 Redirect URL

I'm attempting to sign in users with the LinkedIn Omniauth 2 gem. I have tried a few different possibilities for the redirect, read several articles and nothing is working.
I'm trying to test this locally.
Rails 4 app
Gems include:
omniauth
omniauth-linkedin-oath2
A few attempts of the redirect URL to put in the box includ:
https://www.linkedin.com/uas/oauth2/authorization?client_id=759dczzx23nyic&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Flinkedin%2Fcallback&response_type=code&scope=r_basicprofile+r_emailaddress&state=8da572e31a8e66e6b1de54acddd14937d976ed06d7ed3217&client_id=*
= API Key that needs to stay private
http://localhost:3000
http://localhost:3000/
http://www.localhost:3000
https://localhost:3000
https://localhost:3000/
https://www.localhost:3000
I read both of these articles the entire way through, but still couldn't attempt to find the correct way to redirect it.
https://developer.linkedin.com/forum/register-your-oauth-2-redirect-urls
https://developer.linkedin.com/forum/oauth-20-redirect-url-faq-invalid-redirecturi-error
Any help in what I need to change would be great.
They need to match exactly what you are sending:
http://localhost:3000/auth/linkedin/callback
In case of Linkedin Authorized Redirect URLs should be in form of:
http://localhost:8080/your-project-name/auth/linkedin
After authentication if you want to redirect to a specific page then
http://localhost:8080/your-project-name/that-page-url
I was having a similar issue and kept getting "Invalid redirect_uri. This value must match a URL registered with the API Key." error when using Auth0
I added URL below to LinkedIn's list of allowed callback then it worked.
https://"Insert your Client Domain Name from Auth0"/login/callback

Process post request with rails

A little background info so you can know my overall goal:
I have a web app that uses rails and Devise for authentication. I also am making an iPhone app which I need to be able to send and retrieve data to/from this app. I've decided to make a custom token authentication system in order to handle this.
I want to be able to send a username and password in JSON format as a post request to my app, have the app get that username and password, then have the app reply with a token in an xml or JSON format.
How do I make an action that will get information from a post request (username and password) and process it then return something else?
I just recently attended a meetup that explained Helios, which sounds like what you are looking for.
Check out their docs. Also this Github is an example of helios in action.

Check if the client browser responds to URL with rails

I send emails to my iOS customers with links to our app. When they tap the link, I want to check if they have the app installed.
If the app is installed I want to open it. If not it will redirect to download the app in the App Store.
The URL I'm using to open the app is:
rva://store?uuid=EFBBD9FF-3976-4816-8B77-C1462C99E256
And the check I was using is:
def responds_to_url?(url)
response = Net::HTTP.get_response(URI(url)).code
if response == "200"
return true
else
false
end
end
The problem is that passing my URL above to URI() returns a Generic (capital G) URI object, whereas it should (if it were http) return an HTTP object.
How can I do a similar check with just a link (i.e. no javascript)?
I thought about passing the URL to Mobile Safari and seeing if it responds, but I don't know how to do that or even if it's possible.
You could do client browser detection with HTTP_USER_AGENT, I believe there is a gem for that: Rails Browser Detection Methods
What you describe is not possible. Your rails app will have very limited knowledge of the client—mostly in the form of the User Agent—and there is no way for your Rails app to query for more information while handling a request.

Facebook: stay in canvas after oauth callback

I'm working on an app using facebook & oauth. The app lives inside a facebook canvas, and the authentication is done server side. The app is done w/ Ruby on Rails 3.2, using Koala for dealing with the api (and mongodb as backend, for what it's worth), and hosted on heroku.
So, I supply the heroku url as redirect_url for the callback. Which makes the user go out of the canvas after the authentication, and well, I want it to stay inside. I read a few threads about this that suggested I redirect to the canvas url with js once the authentication is done. I did that, but now it seems that my session token is never set, and the user goes through the auth flow every time he tries to see a non-public page (which means he loops on the welcome page, having an "invisible" exchange with facebook each time).
I don't really get what I'm doing wrong here, so any help is welcome. If you need more informations, just ask.
Thanks for your time!
So I found what was my problem : the page my canvas pointed to was a "public" page, and did not handle anything authentication related, meaning it didn't parse the signed_request, or anything else. I ended up setting a special endpoint for the canvas in charge of handling the signed_request logic, and now it works as one would expect.

Routing Error on PayPal Re-direct

I'm having an issue integrating PayPal into my Rails 3 app using Ryan Bates's screencasts as a guide ( http://railscasts.com/episodes/143-paypal-security).
After payment's complete on the PayPal sandbox, the user's redirected back to the correct URL. Everything from encryption to IPN works great.
For some reason, though, Rails throws a routing error immediately when the user's redirected from PayPal--even though the resource exists. The page repeats the error when I refresh the page, but when I navigate to the URL on my own it renders correctly. The routing error only occurs when PayPal redirects to my app.
I'm using Rails 3.0.10 with Ruby 1.9.2.
Has anyone ever seen this before? What's the cause?
Thanks!
If I remember correctly, the production version of PayPal does a POST of the redirect URL, while the sandox would do a GET. Which is, I know, weird!
Can you change your route for the specific redirect action to match instead of get and try again!?
Also, make sure you exempt it from protect_from_forgery :)

Resources