-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43c431a
commit 80d9aaa
Showing
28 changed files
with
1,095 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
engines: | ||
duplication: | ||
enabled: true | ||
config: | ||
languages: | ||
- ruby | ||
- javascript | ||
- python | ||
- php | ||
fixme: | ||
enabled: true | ||
rubocop: | ||
enabled: true | ||
ratings: | ||
paths: | ||
- "**.inc" | ||
- "**.js" | ||
- "**.jsx" | ||
- "**.module" | ||
- "**.php" | ||
- "**.py" | ||
- "**.rb" | ||
exclude_paths: | ||
- spec/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
service_name: travis-ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,10 @@ | ||
*.gem | ||
*.rbc | ||
/.config | ||
/.bundle/ | ||
/.yardoc | ||
/Gemfile.lock | ||
/_yardoc/ | ||
/coverage/ | ||
/InstalledFiles | ||
/doc/ | ||
/pkg/ | ||
/spec/reports/ | ||
/spec/examples.txt | ||
/test/tmp/ | ||
/test/version_tmp/ | ||
/tmp/ | ||
|
||
# Used by dotenv library to load environment variables. | ||
# .env | ||
|
||
## Specific to RubyMotion: | ||
.dat* | ||
.repl_history | ||
build/ | ||
*.bridgesupport | ||
build-iPhoneOS/ | ||
build-iPhoneSimulator/ | ||
|
||
## Specific to RubyMotion (use of CocoaPods): | ||
# | ||
# We recommend against adding the Pods directory to your .gitignore. However | ||
# you should judge for yourself, the pros and cons are mentioned at: | ||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control | ||
# | ||
# vendor/Pods/ | ||
|
||
## Documentation cache and generated files: | ||
/.yardoc/ | ||
/_yardoc/ | ||
/doc/ | ||
/rdoc/ | ||
|
||
## Environment normalization: | ||
/.bundle/ | ||
/vendor/bundle | ||
/lib/bundler/man/ | ||
|
||
# for a library or gem, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
# Gemfile.lock | ||
# .ruby-version | ||
# .ruby-gemset | ||
|
||
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: | ||
.rvmrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ruby: | ||
config_file: .rubocop.yml | ||
|
||
fail_on_violations: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
AllCops: | ||
Exclude: | ||
- spec/**/* | ||
- db/**/* | ||
|
||
Style/FrozenStringLiteralComment: | ||
Enabled: false | ||
Style/StringLiterals: | ||
EnforcedStyle: single_quotes | ||
Metrics/MethodLength: | ||
Max: 15 | ||
Metrics/LineLength: | ||
Max: 120 | ||
Style/Lambda: | ||
Enabled: false | ||
Style/DotPosition: | ||
Enabled: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
language: ruby | ||
cache: bundler | ||
bundler_args: --without yard guard benchmarks | ||
notifications: | ||
email: false | ||
|
||
addons: | ||
code_climate: | ||
repo_token: a79dc140c09279df903bea582c17d13eecb4e8d80a4d92e1e14f177c74547cc6 | ||
|
||
matrix: | ||
allow_failures: | ||
- rvm: ruby-head | ||
include: | ||
- rvm: 2.2.6 | ||
- rvm: 2.3.3 | ||
- rvm: 2.5.0 | ||
- rvm: ruby-head | ||
|
||
after_success: | ||
- bundle exec codeclimate-test-reporter | ||
|
||
before_install: | ||
- gem install bundler -v '~> 1.10' | ||
- bundle install | ||
- rake db:create | ||
- rake db:migrate | ||
|
||
script: | ||
- rspec spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
source 'https://rubygems.org' | ||
|
||
gemspec | ||
|
||
group :test do | ||
platforms :ruby, :mswin, :mswin64, :mingw, :x64_mingw do | ||
gem 'sqlite3' | ||
end | ||
|
||
gem 'activerecord' | ||
gem 'rubocop', '~> 0.49.0', require: false | ||
|
||
gem 'codeclimate-test-reporter', '~> 1.0.0' | ||
gem 'coveralls', require: false | ||
gem 'database_cleaner', '~> 1.5.0' | ||
gem 'ffaker' | ||
gem 'otr-activerecord', '~> 1.2.1' | ||
gem 'rspec-rails', '~> 3.6' | ||
gem 'simplecov', require: false | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,88 @@ | ||
# activerecord_simple_oauth2 | ||
ActiveRecord mixin for simple_oauth2. | ||
# ActiveRecord SimpleOAuth2 | ||
|
||
## Installation | ||
|
||
Add this line to your application's *Gemfile:* | ||
|
||
```ruby | ||
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](https://github.com/simple-oauth2/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: | ||
```ruby | ||
# app/models/access_token.rb | ||
|
||
class AccessToken | ||
include ActiveRecord::Simple::OAuth2::AccessToken | ||
end | ||
``` | ||
|
||
***AccessGrant*** class: | ||
```ruby | ||
# app/models/access_grant.rb | ||
|
||
class AccessGrant | ||
include ActiveRecord::Simple::OAuth2::AccessGrant | ||
end | ||
``` | ||
|
||
***Client*** class: | ||
```ruby | ||
# app/models/client.rb | ||
|
||
class Client | ||
include ActiveRecord::Simple::OAuth2::Client | ||
end | ||
``` | ||
|
||
***User*** class: | ||
```ruby | ||
# 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](https://github.com/simple-oauth2/activerecord_simple_oauth2/tree/master/db/migrations/20180204143133_create_schema.rb) | ||
|
||
And that's it. | ||
Also you can take a look at the [mixins](https://github.com/simple-oauth2/activerecord_simple_oauth2/tree/master/lib/activerecord_simple_oauth2/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 | ||
|
||
1. Fork the project. | ||
1. Create your feature branch (`git checkout -b my-new-feature`). | ||
1. Implement your feature or bug fix. | ||
1. Add documentation for your feature or bug fix. | ||
1. Add tests for your feature or bug fix. | ||
1. Run `rake` and `rubocop` to make sure all tests pass. | ||
1. Commit your changes (`git commit -am 'Add new feature'`). | ||
1. Push to the branch (`git push origin my-new-feature`). | ||
1. Create new pull request. | ||
|
||
Thanks. | ||
|
||
## License | ||
|
||
The gem is available as open source under the terms of the [MIT License](https://github.com/simple-oauth2/activerecord_simple_oauth2/blob/master/LICENSE). | ||
|
||
Copyright (c) 2018 Volodimir Partytskyi (volodimir.partytskyi@gmail.com). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
ENV['RACK_ENV'] = 'test' | ||
|
||
require 'bundler/setup' | ||
require 'rspec/core/rake_task' | ||
require 'simple_oauth2' | ||
load 'tasks/otr-activerecord.rake' | ||
|
||
OTR::ActiveRecord.db_dir = 'db' | ||
OTR::ActiveRecord.migrations_paths = ['db/migrations'] | ||
|
||
desc 'Default: run specs.' | ||
task default: :spec | ||
|
||
namespace :db do | ||
task :environment do | ||
require_relative 'config/db' | ||
end | ||
end | ||
|
||
RSpec::Core::RakeTask.new(:spec) do |config| | ||
config.verbose = false | ||
end | ||
|
||
Bundler::GemHelper.install_tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# coding: utf-8 | ||
|
||
lib = File.expand_path('../lib', __FILE__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
|
||
require 'activerecord_simple_oauth2/version' | ||
|
||
Gem::Specification.new do |s| | ||
s.name = 'activerecord_simple_oauth2' | ||
s.version = ActiveRecord::Simple::OAuth2.gem_version | ||
s.date = '2017-01-17' | ||
s.summary = 'Mixin for ActiveRecord ORM' | ||
s.description = 'ActiveRecord mixin for SimpleOAuth2 authorization' | ||
s.authors = ['Volodimir Partytskyi'] | ||
s.email = 'volodimir.partytskyi@gmail.com' | ||
s.homepage = 'https://github.com/simple-oauth2/activerecord_simple_oauth2' | ||
s.license = 'MIT' | ||
|
||
s.require_paths = %w[lib] | ||
s.files = Dir['LICENSE', 'lib/**/*'] | ||
|
||
s.required_ruby_version = '>= 2.2.2' | ||
|
||
s.add_runtime_dependency 'simple_oauth2', '0.1.0' | ||
|
||
s.add_development_dependency 'rspec-rails', '~> 3.6.0', '>= 3.6.0' | ||
s.add_development_dependency 'database_cleaner', '~> 1.5.0', '>= 1.5.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'bundler/setup' | ||
require 'activerecord_simple_oauth2' | ||
|
||
require 'irb' | ||
IRB.start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
OTR::ActiveRecord.configure_from_hash!(adapter: 'sqlite3', database: ':memory:') | ||
|
||
ActiveRecord::Base.logger = nil | ||
ActiveRecord::Migration.verbose = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
class CreateSchema < ActiveRecord::Migration[5.0] | ||
def change | ||
create_table :users do |t| | ||
t.string :username, null: false, unique: true | ||
t.string :encrypted_password, null: false | ||
|
||
t.timestamps null: false | ||
end | ||
|
||
create_table :clients do |t| | ||
t.string :name, null: false | ||
t.string :redirect_uri, null: false | ||
t.string :key, null: false, unique: true, index: true | ||
t.string :secret, null: false, unique: true, index: true | ||
|
||
t.timestamps null: false | ||
end | ||
|
||
create_table :access_tokens do |t| | ||
t.integer :resource_owner_id, null: false, index: true | ||
t.integer :client_id, null: false, index: true | ||
|
||
t.string :token, null: false, unique: true, index: true | ||
t.string :refresh_token, unique: true, index: true | ||
t.string :scopes | ||
|
||
t.datetime :revoked_at | ||
t.datetime :expires_at, null: false | ||
|
||
t.timestamps null: false | ||
end | ||
|
||
create_table :access_grants do |t| | ||
t.integer :resource_owner_id, null: false, index: true | ||
t.integer :client_id, null: false, index: true | ||
|
||
t.string :token, null: false, unique: true, index: true | ||
t.string :redirect_uri, null: false | ||
t.string :scopes | ||
|
||
t.datetime :revoked_at | ||
t.datetime :expires_at, null: false | ||
|
||
t.timestamps null: false | ||
end | ||
end | ||
end |
Oops, something went wrong.