Git Product home page Git Product logo

opro's Introduction

oPRO

A production ready Rails Engine that turns your app into an OAuth2 Provider.

oPRO is short for (O)Auth (Pro)vider and is pronounced "oh proh". Not to be confused with Oprah, who does not support or endorse this ruby gem in any way (yet).

Build Status Code Climate

Why would I use this?

Lets say you've built a Rails app, awesome. Now you want to build a mobile app on say, the iPhone... cool. You start throwing around #to_json like nobody's business, but then you realize you need to authenticate users somehow. "Basic Auth!!", you exclaim, but then you realize that's not the most secure solution. You also realize that some users already signed up with Facebook & Twitter so they don't have a username/password combo. What ever shall you do?

Wouldn't it be great if we could have a token exchange where the user goes to a mobile web view and grants permission, and then we return back an auth token just like the big boys (Facebook, Twitter, cough Foursquare cough). With oPRO, we can add this functionality pretty easily. We'll use your existing authentication strategy and provide some integration end points for your clients to use out of the box.

Install

Gemfile

gem 'opro'

Then run

$ bundle install

and don't forget

$ rails g opro:install

This will put a file in initializers/opro.rb, generate some migrations, and add mount_opro_oauth to your routes.

Now we're ready to migrate the database

$ rake db:migrate

This will add Opro::Oauth::AuthGrant and Opro::Oauth::ClientApp to your database. An iPhone app would need to register for a client_id and client_secret before using OAuth as a ClientApp. Once created they could get authorization from users by going through the OAuth flow, thus creating AuthGrants. In other words, a ClientApp has many users through AuthGrants.

Setup

Go to initializers/opro.rb and configure your app for your authentication scheme. If you're not using devise, see "Custom Auth" below.

Opro.setup do |config|
  config.auth_strategy = :devise
end

Now in your controllers you can allow OAuth access using the same syntax of the rails before_filter

class UsersController < ApplicationController
  allow_oauth!  :only => [:show]
end

You can also disallow OAuth on specific actions. Disallowing will always over-ride allowing.

class ProductsController < ApplicationController
  disallow_oauth!   :only => [:create]
end

By default, all OAuth access is blacklisted. To whitelist all access, add allow_oauth! to your ApplicationController (this is not recommended). The best practice is to add allow_oauth! or disallow_oauth to each and every controller.

That should be all you need to do to get set up. Congrats, you're now able to authenticate users using OAuth!!

Use it

oPRO comes with built in documentation, so if you start your server you can view the docs at http://localhost:3000/oauth_docs. Or you can view the guide on the example app. This guide will walk you through creating your first OAuth client application, giving access to that app as a logged in user, getting an access token for that user, and using that token to access the server as an authenticated user!

Keep in mind that the OAuth client application is associated to the user creating it. If you have multiple administrators for oPRO, be aware that the web interface is currently only useful to the user that created it.

Advanced Setup

oPRO is simple by default, but easily configurable for a number of common use cases. Check out the options below.

Custom Auth

If you're not using devise, you can manually configure your own auth strategy. In the future I plan on adding more auth strategies; ping me or submit a pull request for your desired authentication scheme.

Opro.setup do |config|
  config.login_method             { |controller, current_user| controller.sign_in(current_user, :bypass => true) }
  config.logout_method            { |controller, current_user| controller.sign_out(current_user) }
  config.authenticate_user_method { |controller| controller.authenticate_user! }
end

Permissions

When a user authenticates with a client, they are automatically granting read permission to any action that you allow_oauth!. Read-only clients are restricted to using GET requests. By default, oPRO will ask users for write permission on a client by the client application. Client apps with :write permission can use all HTTP verbs including POST, PATCH, PUT, DESTROY on any url you whitelist using allow_oauth!.

Custom Permissions

To remove write permissions, comment out this line in the oPRO initializer:

config.request_permissions = [:write]

You can add custom permissions by adding to the array:

config.request_permissions = [:write, :email, :picture, :whatever]

You can then restrict access using the custom permissions by calling require_oauth_permissions, which takes the same arguments as before_filter:

require_oauth_permissions :email, :only => :index

You can also skip permissions using skip_oauth_permissions. By default, permissions will just check to see if a client has the permission and will allow the action if it is present. If you want to implement custom permission checks, you can write custom methods using the pattern oauth_client_can_#{permission}?. For example, if you were restricting the :email permission, you would create a method:

def oauth_client_can_email?
  # ...
end

The result is expected to be true or false.

Refresh Tokens

For added security, you can require access_tokens to be refreshed by client applications. This will help to mitigate the risk of a leaked access_token and enable an all around more secure system. This security comes at a price, however, since implementing the refresh_token functionality in a client can be more difficult.

By default, refresh tokens are enabled. You can disable them in your application and set the timeout period of the tokens by adding this line to your configuration:

config.require_refresh_within = false

Toggling Refresh Tokens

If you disable refresh tokens and then re-enable it you may have authorization grants that do not have a timeout listed, you can keep it like this or you can fix by iterating through all auth grants and setting their access_token_expires_at like this:

Opro::Oauth::AuthGrant.find_each(:conditions => "access_token_expires_at is null") do |grant|
  grant.access_token_expires_at = Time.now + ::Opro.require_refresh_within
  grant.save
end

You may also need to inform clients that they need to update their credentials and start using refresh tokens.

Password Token Exchange

If a client application has a user's password and username/email, they can exchange these for a token. This is much safer than storing the username and password on a local device, but it does not offer the traditional OAuth "Flow". Because of this, all available permissions will be granted to the client application. If you want to disable this feature you can set the configuration below to false:

config.password_exchange_enabled = true

If you have this feature enabled, you can further control what applications can use the feature. Some providers may wish to have "Blessed" client applications that have this ability while restricting all other clients. To accomplish this, you can create a method in your ApplicationController called oauth_valid_password_auth? that accepts a client_id and client_secret and returns true or false based on whether that application can use password auth:

def oauth_valid_password_auth?(client_id, client_secret)
  BLESSED_APP_IDS.include?(client_id)
end

If you are using this password functionality without a supported authorization engine (like devise), you will need to add an additional method that supports validating whether or not a user's credentials are valid. The method for this is called find_user_for_auth and accepts a controller and the parameters. The output is expected to be a user. Add this to your config like you did to the other required methods in the "Custom Auth" section:

config.find_user_for_auth do |controller, params|
  # user = User.find(params[:something])
  # return user.valid_password?(params[:password]) ? user : false
end

If you're authenticating by exchanging something other than a password (such as a facebook auth token), clients can still enable this functionality by setting params[:grant_type] == 'password' in their initial request. You can then use the find_user_for_auth method from above and implement your custom behavior. You can call find_user_for_auth multiple times and the application will try calling each auth method in order. It is suggested that you return from this block early if the params are missing a vital key like this:

config.find_user_for_auth do |controller, params|
  return false if params[:fb_token].blank?
  User.where(:fb_token => params[:fb_token]).first
end

Rate Limiting

If your API becomes a runaway success and people start abusing your API, you might choose to limit the rate that client applications can access your API. It is common for popular read-only APIs to have an hourly or daily rate limit to help prevent abuse. If you want this type of functionality, you can use oPRO's built in hooks: one to record the number of times a client application has accessed your API and another to let the application know if the Client app has gone over its allotted rate.

To record the number of times an application has accessed your site add this method to your ApplicationController:

def oauth_client_record_access!(client_id, params)
  # implement your rate counting mechanism here
end

Then to let our server know if a given client has reached its limit, add the method below. The output is expected to be true if the client has gone over their limit and false if they have not:

def oauth_client_rate_limited?(client_id, params)
  # implement your own custom rate limiting logic here
end

Rate limited clients will receive an "unsuccessful" response to any query with a message letting them know they've been rate limited. Using redis with a rotating key generator based on (hour, day, etc.) is one very common way to count accesses and implement the rate limits. Since there are so many different ways to implement this, we decided to give you a blank slate and let you implement it however you would like. The default is that apps are not rate limited, and in general unlimited API access is the way to go, but if you do find abusive behavior you can always easily add in a rate limit.

Configurable Authorization Header

By default, oPRO allows clients to send their authorization token in a header. For example, someone using an auth token of 9693accessTokena7ca570bbaf could set the Authorization header in a request like this:

    $ curl -H "Authorization: Bearer 9693accessTokena7ca570bbaf" "http://localhost:3000/oauth_test/show_me_the_money"

By default, oPRO will accept Bearer and token in the authorization header, but if your client needs to send a custom auth header, you can add a custom extra regular expression to parse and return the token. For example, if a client was setting the auth header like this:

    $ curl -H "Authorization: cUsTomAuthHeader 9693accessTokena7ca570bbaf" "http://localhost:3000/oauth_test/show_me_the_money"

You could pull out the auth token using the regular expression /cUsTomAuthHeader\s(.*)/. If you're not great with regular expressions, I highly recommend using Rubular to test regex matches. It is very important that we are "capturing" data in between the () characters. The data returned inside of the parens is expected to be the auth token with no spaces or special characters such as new lines or quotes. To parse this auth header in oPRO, you can specify the header_auth_regex in an initializer like this:

Opro.setup do |config|
  config.auth_strategy = :devise

  config.header_auth_regex = /cUsTomAuthHeader\s(.*)/
end

Now when a client sends your custom auth header, it will be parsed correctly. Custom authorization headers should not be used for security through obscurity. They may be exposed in the docs or tests in a later iteration of oPRO. If you have strong feelings against this, then please open a pull request or send me a message stating your case.

Customizing Views & Controllers

By default oPRO ships with views and controllers much like Devise. You can use the built in oPRO views, and change styles: all oPRO views should be wrapped with an opro class you can use for styling. For more control you can override oPRO views with your own views. To do this you will need to provide your own routes/controllers/views. You can override oauth_docs_controller, oauth_docs_controller, and oauth_client_apps_controller.

Currently this is a manual process to give you control and understanding of what is happening behind the scenes, if you want to work on a generator, I will be happy to help you...ping me @schneems. To make things a little more clear we are going to be referencing the oPRO demo rails app.

To start out overriding a controller we need to specify the new controller in your routes inside of mount_opro_oauth, for example if you wanted to over-ride the oauth_client_apps controller with a controller in app/controllers/oauth/client_apps_controller.rb you could specify it like this:

mount_opro_oauth :controllers => {:oauth_client_apps => 'oauth/client_apps'}

You can see an example of setting the routes in the oPRO demo rails app. Of course you then need to create the controller, it needs to inherit from the original controller Opro::Oauth::ClientAppController like this:

class Oauth::ClientAppsController < Opro::Oauth::ClientAppController
end

You can see an example of a: custom oPRO controller. Once you've got your controller finished, you need to specify your custom oPRO views.

It may help to look at the current oPRO controllers and current oPRO views. Again, if you get stuck take a look at the oPRO demo rails app.

Skipping Views

If you do not wish for test, docs, or client_apps views & controllers to be available, you can skip them using except in your mount_opro_oauth like this:

mount_opro_oauth :except => [:oauth_client_apps]

We recommend against doing this, but we aren't your mother.

If you don't need auth routes because you are only using "Password Token Exchange" you can use except like this:

mount_opro_oauth :except => [:auth]

or if you don't need docs and tests too:

mount_opro_oauth :except => [:auth, :docs, :tests]

Assumptions

  • You have a user model and that is what you're authenticating
  • You're using Active Record

About

If you have a question file an issue or find me on the Twitters @schneems. Another good library for turning your app into an OAuth provider is Doorkeeper, if this project doesn't meet your needs let me know why and use them :)

This project rocks and uses MIT-LICENSE.

opro's People

Contributors

audionerd avatar bodrovis avatar carols10cents avatar cicloid avatar dtykocki avatar elia avatar nvh avatar omcnet avatar psagan avatar robe5 avatar schneems avatar texasjusticar avatar twinge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

opro's Issues

Client's User must accept permission/scope everytime

Hi schneems,

We have a new issue with rails4:

  1. after user login, user will be asked whether accept permission read/write for the app.
  2. User agree
  3. Next time, user login again, and user will be asked to accept the permission again.

I remember that I did not have this issue when develop the app for Rails 3 before.

Thank you.
P/S: Is there any customization we can made to by pass the "permission" request for some specific app?

Not playing nice with strong_params

First off, awesome gem... I can log in but I can't update a user

I'm getting this error

Parameters: {"user"=>{"email"=>"[email protected]"}}
Completed 401 Unauthorized in 99ms

What I'm using

 def update
    @user = current_user
    @user.update_attributes(resource_params)
    respond_to do |format|
      format.json do
        render :json => @user.to_public_json
      end
      format.html do
        render :edit
      end
    end
  end

Routes

put "users/edit", :to => 'users/registrations#update'

Rails4, opro:install just hang

Hi ,

Thank you for a great gem,

We are using Rails4 and just stuck at this phase:

localhost: $ rails g opro:install
Warning: You're using Rubygems 2.0.7 with Spring. Upgrade to at least Rubygems 2.1.0 and run gem pristine --all for better startup performance.
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
create config/initializers/opro.rb
generate active_record:opro
Warning: You're using Rubygems 2.0.7 with Spring. Upgrade to at least Rubygems 2.1.0 and run gem pristine --all for better startup performance.

Omniauth example

I think an Omniauth exmaple or readymade strategy would be helpful

(of course I'll PR something if I'll be able to extract it from current work)

mount oPro into namespace

Hi Richard,

I've try to mount oauth part of oPro into root namespace and client_app and docs into admin namespace and Routing Error was raised.

routes.rb

Rails.application.routes.draw do
   ...
   mount_opro_oauth :except => [:client_apps, :docs, :tests]
   namespace :system_admin do
     mount_opro_oauth :except => [:tests]
     ...
   end
   ...
end

raised error:

ActionController::RoutingError (uninitialized constant SystemAdmin::Opro):
  lib/rack/ie_compatibility.rb:8:in `call'
  lib/rack/env_logger.rb:10:in `call'
  config/initializers/quiet_assets.rb:7:in `call_with_quiet_assets'

It does currently not support the bearer scheme

Currently the library expects to get the access-token either via a get parameter or an authorization header, holding the token.
However the method that extracts this token doesn't work with the Bearer authentication scheme, which seems to be used by the latest omniauth-oauth2 gem. The problem is Opro::Controllers::ApplicationControllerHelper#oauth_access_token_from_header
which checks for the "tokens" string but not for the "Bearer" string, which would be present if the Bearer authentication scheme is used. Thus the client can never authorize. The fix seems to be simple, but i don't know if this is something you want to support so i just opened a ticket instead of issuing a pull request. I'm not that familiar with OAuth so please tell me your thoughts about this.

Greetings

opro implementation issue

I have created a simple user module in rails. I have successfully implemented devise. It is working. I am using MySQL database. Rails Version is 4.1.4 and ruby is 2.1.2. I have implemented opro on my application and tried to authorize a new user. First I logged in as John(user), then opened the link, http://localhost:3000/oauth_docs, and followed the steps of authorization. Then I go to http://localhost:3000/oauth/new?client_id=12f9c2f1cd50cde7fa2008164b3d52be&client_secret=24327f607e7a57e944425e9267febbe1 this link for granting authorization to the user(here client id and client_secret are generated by following the steps). Then when I click on Authorize this application button, following error was encountered::

NoMethodError in Opro::Oauth::AuthController#create
undefined method `<<' for nil:NilClass

And when I clicked decline this request button, then got routing error::
No route matches [POST] "/".

Please help me to implement opro and generate access token for users.

How to override auth_controller

Hi schneems,

We want to encrypt client_id and client_secret by base64, and will decrypt it at server side.

And we just require only some applications to perform this encryption, the other apps are not required.

How can we override this controller:
https://github.com/opro/opro/blob/master/app/controllers/opro/oauth/auth_controller.rb

Or else, is there any other way around to perform encrypt/decrypt client_id&client_secret for some specific applications without overriding auth_controller?

Thank you

Can't edit a client application's name, but instructions say I can

In the docs and on the new client application form, it says to not worry about what you name a client application because you can change it later-- but I don't see edit/update actions or views or links anywhere.

I'd be fine either with removing the documentation that says this is possible or actually enabling this ability.

Sorcery?

I'm struggling with properly configuring opro.rb for Sorcery.

I have the following:

config.login_method             { |controller, current_user| controller.login(current_user, bypass: true) }
  config.logout_method            { |controller, current_user| controller.logout(current_user) }
  config.authenticate_user_method { |controller| controller.authenticates_with_sorcery! }

But this throws an error when visiting .../oauth_client_apps/new:

undefined method `authenticates_with_sorcery!' for #Opro::Oauth::ClientAppController:0x007f894cb15ee0

Is it possible to customize the oauth/new view

I would like to customize the view for teh authorization request

http://localhost:3000/oauth/new?action=create&client_id=311addadb6db90050177036e4e19f4ed&redirect_uri=%2Foauth_walkthrough%2Fget_access_token%3Fclient_id%3D311addadb6db90050177036e4e19f4ed

currently is rendered by the engine ,

Rendered /Users/yves/.rvm/gems/ruby-1.9.3-p392@rails32/gems/opro-0.4.3/app/views/opro/oauth/auth/new.html.erb within layouts/application

where should I add the view ?

thanks for feedback

about access_token_expires_at

Hi schneems,

I love your code, it's very easy to use.
is it possible to refresh access token?

thanks. :)
Best regards!

undefined local variable or method `controller'

In my test app I've redefined config.request_permissions like this:

config.request_permissions = [:update]

Then in the controller I am doing this:

allow_oauth!
require_oauth_permissions :update, only: :update

However when trying to call update with all necessary parameters specified, I am keep getting

undefined local variable or method controller for #<Api::UsersController:0x9a2a0b0>

It fails here

controller.skip_oauth_required_permission(permission)
so basically it does not know what controller is. Everything was working okay up to this point.

Here are two apps to reproduce this issue https://github.com/bodrovis/Sitepoint-source/tree/master/Auth_Provider_with_Opro (client and server). Here are the corresponding lines:

Steps to reproduce:

  • bundle install
  • apply migrations
  • boot server app, register a new app
  • inside config directory of client's app create local_env.yml file with the contents like
opro_base_url: 'http://localhost:3000'
opro_client_id: ''
opro_client_secret: ''

My server app was running at port 3000, so I specified opro_base_url like that.

  • Boot client app, click "Authenticate via oPRO", accept permissions request and click "Update a user" link. The error should appear after this.
    Any help is very much appreciated!

P.S. When using default write permission and commenting out require_oauth_permissions everything is working fine.

Customizing Opro::Oauth::TokenController

Hello!

Currently I am writing an article about opro (probably you've seen it on Sitepoint's Trello board). It seems that TokenController is not meant to be customizable, however what I wanted to do is to return a bit more information when presenting a token, for example, some info about a user who is authenticating.

render :json => { access_token: auth_grant.access_token,
Like, you know, when authenticating via Twitter we get a pretty big hash of various data about a user apart from token (name, avatar, followers count etc). I could've created some custom controller action and after receiving a token just make individual request there, but that seems a bit cumbersome to me.

Maybe you could recommend something? I'd be very grateful. :)

Lost session of current_user

  1. Login with user A

  2. Send request with access_token of user A.

After request with asscess_token then user A lost session. User A automatic logout

Rails 4 compatibilty

Hello,

I'm currently trying to make opro play nice with Rails 4. Apart from routes (see #28 ), the other blocking point I've seen so far is the use of attr_accessible in some models.

I can see 2 options to fix it:

  1. Add strong_parameters in dependencies, and make some adjustments in controllers
  2. Add protected_attributes in dependencies for Rails 4

2 is the easy way, but 1 seems to be the way to go imho.

I'm willing to add a pull-request about this, just state your preference. ๐Ÿ˜„

chatgris

Opro::Oauth::ClientApp doesn't work with attribute whitelisting

create_with_user_and_name calls create with attributes hash internally, which will fail in a rails environment that has set
config.active_record.whitelist_attributes to true.

Unless you want to whitelist these attributes in the model, the creation would have to be done through a new instance and then using the accessors.

error with 'login' virtual attribute ( Devise strategy )

In my rails app, user can authenticate either with their username or email address ,
as per devise doc, ( https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address ), I added a virtual attribute 'login' , which doesn't persist , and a 'find_first_by_auth_conditions' method in the user model

def self.find_first_by_auth_conditions(warden_conditions)
    conditions = warden_conditions.dup
    if login = conditions.delete(:login)
        where(conditions).where(["lower(username) = :value OR lower(email) = :value", { :value => login.downcase }]).first
    else
        where(conditions).first
    end
end

When running the iphone demo app , an entering the username in the iPhone GUI, an error is raised , stating that the 'login' column doesn't exist ( which is true ... it's a virtual attribute..)
Did you test this case w the Devise strategy ?
I guess I should modify the ' find_user_for_auth' method in lib/opro/auth_provider to check for the :login param ?

Started POST "/oauth/token.json" for 127.0.0.1 at 2013-04-17 18:18:56 +0200

Processing by Opro::Oauth::TokenController#create as JSON
  Parameters: {"password"=>"[FILTERED]", "username"=>"leo", "grant_type"=>"user_basic", "client_secret"=>"2441a916ca077ce0e8c75ec1617ae500", "client_id"=>"856aa93d1e0648e4d73d75aace47a905"}


  Opro::Oauth::AuthGrant Load (0.7ms)  SELECT `opro_auth_grants`.* FROM `opro_auth_grants` WHERE `opro_auth_grants`.`access_token` IS NULL LIMIT 1

  Opro::Oauth::ClientApp Load (1.0ms)  SELECT `opro_client_apps`.* FROM `opro_client_apps` WHERE (app_id = '856aa93d1e0648e4d73d75aace47a905' AND app_secret = '2441a916ca077ce0e8c75ec1617ae500') LIMIT 1

  User Load (39.5ms)  SELECT `users`.* FROM `users` WHERE `users`.`login` = 'leo' LIMIT 1
Mysql2::Error: Unknown column 'users.login' in 'where clause': SELECT  `users`.* FROM `users`  WHERE `users`.`login` = 'leo' LIMIT 1
Completed 500 Internal Server Error in 563ms

ActiveRecord::StatementInvalid (Mysql2::Error: Unknown column 'users.login' in 'where clause': SELECT  `users`.* FROM `users`  WHERE `users`.`login` = 'leo' LIMIT 1):

not receiving credentials ( standard rails demo + iphone client app )

Before trying to use Devise :login capability ( username or email) , I tried to run the standard way ( Devise :email) , as per your post : http://schneems.com/post/33781154129/would-you-like-a-mobile-app-with-that

everything is running fine , but trying to login with existing user seems to be stopped after authentication, after displaying the NSLog message

Exchanging username and password for OAuth credentials"

I don't get the "Successfully received OAuth credentials" message displayed , and no errors in the Rails console, the opro_auth_grants is created with the access token...

https://gist.github.com/erwin/5425495

I modified the iphone client to check for an error :

  [[OproAPIClient sharedClient] authenticateUsingOAuthWithUsername:userUsernameField.text password:userPasswordField.text
    success:^(AFOAuthAccount *account) {
      NSLog(@"Success: %@", account);
  } failure:^(NSError *error) {
      NSLog(@"Error: %@", error);
  }];

and I get : Error: (null)

When I curl from the console , it seems ok

curl 'http://localhost:3000/oauth/token?client_id=1a1dcfb61b838d2d4138c2e7f956dc86&client_secret=3e4bfb83cafbdbd53e5161fd40da3143&email=leo.fiorillo%40example.com&password=123456789'

=> {"access_token":"b8ef038378aca6757d83ee65b5d5d70e","refresh_token":"eadb0bd8d63fb2272c50c1fa5caa0876","expires_in":false}

curl "http://localhost:3000/users/me.json?access_token=b8ef038378aca6757d83ee65b5d5d70e"

=> {"id":3,"email":"[email protected]","username":"leo","siteID":123,"userID":4567,"zip":"11111","phone_number":"013456789","twitter":"@fiorillo"}

Use Access Token in Header

quite there ... integrated the opo demo in my app... , final step .. all curl call running fine excepte the last one ...

Use Access Token in Header
You can also use a header to pass the oauth token, if you prefer.

curl -H Authorization: token 1b8a6e61063afdb7cee142847f7f33eb http://localhost:3000/oauth_tests/test_me.json

curl -H Authorization: token 1b8a6e61063afdb7cee142847f7f33eb http://localhost:3000/oauth_tests/test_me.json
{"status":"unauthorized","message":"OAuth did not work :( - No OAuth token provided! - OAuth user not found! - OAuth client not permitted- write permission required","params":{"action":"show","controller":"opro/oauth/tests","id":"test_me","format":"json"}}

what did I miss ?

[SOLVED] haml issue in generating the right command , should be : ( header between single quotes ...)

curl -H 'Authorization: token 1b8a6e61063afdb7cee142847f7f33eb' http://localhost:3000/oauth_tests/test_me.json

thanks for your demo ! , going to work on the iPhone app

Support Mongoid as a data model engine

Right now , only active record is supported as data layer, scince mongodb/mongoid is a very popular these days, making support is much appreciated feature

Is there option for assertion grant?

I want to issue token using facebook access token, and register new users as well.
So Is there an option/gem for configuring to use assertion grant in opro. Doorkeeper does that but not really satisfied with it because it issues token without requiring client_id and secret.

Setting `client_id` and `client_secret` from HTTP Basic Auth

The OAuth 2.0 spec recommends Base64 encoding client_id and client_secret via HTTP Basic Auth, whereas opro expects them to be passed as params.

I've been testing this with my TokenController, e.g.:

class Oauth::TokenController < Opro::Oauth::TokenController
  before_action :set_params_from_http_basic_auth, only: [:create]

  def set_params_from_http_basic_auth
    if ActionController::HttpAuthentication::Basic.has_basic_credentials?(request)
      client_id, client_secret = ActionController::HttpAuthentication::Basic.user_name_and_password(request)
      params[:client_id] ||= client_id
      params[:client_secret] ||= client_secret
    end
  end

  [..]
end

Is there a better way to handle this? Looking for advice. Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.