vimeo ruby gem auth_token example for oAuth? - ruby-on-rails

Anyone know what the correct syntax to get an auth_token from Vimeo using the recently updated vimeo gem (http://github.com/matthooks/vimeo) using oAuth?
I'm trying this:
def authorize
base = Vimeo::Advanced::Base.new(VIMEO_API_KEY, VIMEO_SECRET)
redirect_to base.web_login_link("delete")
end #end method
--- get redirected to vimeo, allow access, then get redirected to app with frob variable ---
def callback
vimeo = Vimeo::Advanced::Auth.new(VIMEO_API_KEY, VIMEO_SECRET)
auth_token = vimeo.get_token(params[:frob])
end
-- now I get the following error:
{"err"=>{"msg"=>"Missing required parameter", "code"=>"307", "expl"=>"A required parameter was missing: oauth_consumer_key"}, "stat"=>"fail", "generated_in"=>"0.0054"}
Anyone familiar with this gem or the correct syntax to get the auth_token for making authenticated calls in the future

Based on the documentation on authenticating as a website in the readme, it looks like you're missing a few steps. The github README should have the latest info, so I won't paste it here.
Are you trying to accomplish something other than the example given is showing you how to do?
Have you tried vendoring the code instead of using the gem? Perhaps recent updates weren't deployed as a gem yet, as it does look like OAuth is a new feature based on the github history.

Related

Internal server error response during rails omniauth docusign callback

I am connecting to DocuSign via oauth with Rails 6 and Omniauth - it seems I have it configured correctly since visiting /auth/docusign takes me to the DocuSign login screen. After logging in, it takes me to the callback. The callback is failing because the omniauth-docusign gem is failing with the user_info hash. Where it should be getting user_info['accounts'] it is getting this:
user_info #=> {"error"=>"internal_server_error", "reference_id"=>"a0f0e8c9-2faa-4b70-90b8-875ae40f13cf"}
My API Dashboard for the App shows no log or request info. 0 total requests. Is there a log area for oauth attempts, or where to use this reference ID?
Can someone at DocuSign help with this? Your developer support page seems to say to ask here on S/O.
It appears that you didn't configure everything correctly for your Integration Key (IK which is like clientId) as well as clientSecret and the rest of the configuration that you can do for your IK.
I would suggest that you can get a pre-built Ruby application that already had this all done for you and save you some work by going to the Quickstart. This would enable you to go get a ZIP file pre-configurated with all the required gems and everything needed for auth already set based on your own developer account.
Update: if you then want to take this code into your own app, you need to also get the authentication code supplied lib/docusign.rb instead of a gem like omniauth-docusign.
As Inbar Gazit said, it's important to use the Quickstart app, which I was doing. However, not only do I already have my own existing rails app, even if I didn't, I wouldn't want to have to clean out all the extra stuff in the quickstart app that I don't need. It would be nice to have a minimal script for installing just the bare minimum into an existing rails app to get authenticated and start using the API.
In the end, the solution for me was to notice and copy the lib/docusign.rb file from the Quickstart app, instead of using an omniauth-docusign gem. The base omniauth gem had advised me to find and install that gem because there was no strategy defined for docusign. The quickstart lib file is what I needed.

Where I need to place ruby-trello gem's config code?

I am creating rails API app for managing Trello related boards and lists.
I have decided to use "ruby-trello" gem.
There is a config example at github ruby-trello page (https://github.com/jeremytregunna/ruby-trello).
Config looks like this:
Trello.configure do |config|
config.developer_public_key = 'my_trello_key'
config.member_token = 'my_trello_token'
end
I got key and token from trello devs.
I have added this code to my config/application.rb in class Application.
But when I am trying to get something data from Trello I see this error:
Trello::ConfigurationError (Trello has not been configured to make authorized requests.)
Can anybody help? Where I need to place this config code?
Sorry for my English.
The Rails convention is to put that in config/initializers/trello.rb so that it's picked up when Rails boots.
It's odd they don't seem to mention that in the documentation.

Enabling CORS for IGDB using ruby on rails?

So I've been at this issue for hours now but cannot figure it out. I've been trying to use the IGDB API using the ruby gem igdb_api but keep getting a 403 Forbidden exception. I'm running the server locally for development at localhost:3000. Here is how I setup my test code:
class PagesController < ApplicationController
def home
...
end
def games
# initialize with api_key
Igdb.connect(ENV['IGDB_API_KEY'])
puts Igdb::Game.count
end
end
I've been trying to use rack-cors to fix this but nothing changes. So I'm not sure if I'm missing something obvious. Any help would be great! Thank you.
I don't think cors is an issue.
CORS basically prevents web-browser from making requests to services outside of current domain.
403 errors means some authorization problems.
I ended up using a different gem for accessing the api, one called igdb_client.
While I then had a SSL_connection error since I'm on Windows, it was easily fixed by following this quick solution here: https://superdevresources.com/ssl-error-ruby-gems-windows/.
Hope it'll help anyone in the future!

Rails get username of currently logged windows user

I need to get the username of the currently logged windows user. Could it be done easily?
The username of the account running the script can be accessed via something like:
puts ENV['USERNAME']
Beware that if you're running it as a system service the username will probably come back as "SYSTEM"
If that isn't enough to suite your needs there is an alternative method outlined here: https://stackoverflow.com/a/3544741/648695
You can use the Ruby etc module
require 'etc'
Etc.getlogin
The doc is avaiable here: http://ruby-doc.org/stdlib-2.0.0/libdoc/etc/rdoc/Etc.html#method-c-getlogin
Returns the short user name of the currently logged in user.
As far as I know, unless you're using active directory that would require a microsoft framework website, I don't think you'll find a way in rails.
There are a few discussion points here that may help: Can you get a Windows (AD) username in PHP?
Same question here: is there a way to read a clients windows login name using ruby on rails
Anyways, just copying my own answer below...
This is what worked for me but there are some limitations:
won't work in Chrome: undefined method 'encode' for nil:NilClass
won't validate user credentials
If you don't care about these issues, go ahead:
In your rails application, add Rekado's gem to your Gemfile: gem 'ntlm-sso', '=0.0.1'
Create an initialiser config/initializers/ntlm-sso.rb with:
require 'rack'
require 'rack/auth/ntlm-sso'
class NTLMAuthentication
def initialize(app)
#app = app
end
def call(env)
auth = Rack::Auth::NTLMSSO.new(#app)
return auth.call(env)
end
end
On your application.rb file, add the line: config.middleware.use "NTLMAuthentication"
Call request.env["REMOTE_USER"] on your view or controller to get current username.
PS: Let me know if you find anyway to make it work on Chrome or to validate user credentials.

Ruby on Rails - Prompting user for password

I'm trying to add some basic file-download functionality to my Rails application and have the password_hash and password_salt fields for my file model. I also have a function in which a download link to the file is generated, however I'm not totally sure (as I'm sort of reasonably new to Ruby and Rails) how I'd go about actually prompting the user for a password and checking this before proceeding with the file download.
Any help would be appreciated.
You should target you link to a controller and send the file like this:
before_filter :login_required
def download
send_file '/home/railsway/downloads/huge.zip', :type=>"application/zip"
end
this way you can check the password in you before filter using HTTP Basic Auth for example.
more info: http://www.therailsway.com/2009/2/22/file-downloads-done-right

Resources