ActiveRecord SimpleOAuth2
Installation
Add this line to your application's Gemfile:
gem 'activerecord_simple_oauth2'
And then execute:
$ bundle
Or install it yourself as:
$ gem install activerecord_simple_oauth2
Usage
OAuth2 workflow implies the existence of the next four roles: Access Token, Access Grant, Application and Resource Owner. The gem needs to know what classes work, so you need to create them, and also you need to configure Simple::OAuth2.
Your project must include 4 models - AccessToken, AccessGrant, Client and User for example. These models must contain a specific set of API (methods). So everything that you need, it just include each mixin
to specific class.
AccessToken class:
# app/models/access_token.rb
class AccessToken
include ActiveRecord::Simple::OAuth2::AccessToken
end
AccessGrant class:
# app/models/access_grant.rb
class AccessGrant
include ActiveRecord::Simple::OAuth2::AccessGrant
end
Client class:
# app/models/client.rb
class Client
include ActiveRecord::Simple::OAuth2::Client
end
User class:
# app/models/user.rb
class User
include ActiveRecord::Simple::OAuth2::ResourceOwner
end
Migration for the simplest use case of the gem looks as follows: example
And that's it. Also you can take a look at the mixins to understand what they are doing and what they are returning.
Bugs and Feedback
Bug reports and feedback are welcome on GitHub at https://github.com/simple-oauth2/activerecord_simple_oauth2/issues.
Contributing
- Fork the project.
- Create your feature branch (
git checkout -b my-new-feature
). - Implement your feature or bug fix.
- Add documentation for your feature or bug fix.
- Add tests for your feature or bug fix.
- Run
rake
andrubocop
to make sure all tests pass. - Commit your changes (
git commit -am 'Add new feature'
). - Push to the branch (
git push origin my-new-feature
). - Create new pull request.
Thanks.
License
The gem is available as open source under the terms of the MIT License.
Copyright (c) 2018 Volodimir Partytskyi (volodimir.partytskyi@gmail.com).