authify-api 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +23 -0
  5. data/.travis.yml +13 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +41 -0
  9. data/Rakefile +38 -0
  10. data/authify-api.gemspec +45 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/config.ru +9 -0
  14. data/db/migrate/20170201213901_create_users.rb +12 -0
  15. data/db/migrate/20170201220029_create_api_keys.rb +12 -0
  16. data/db/migrate/20170202004557_create_identities.rb +12 -0
  17. data/db/migrate/20170203231922_create_organizations_and_organization_memberships.rb +22 -0
  18. data/db/migrate/20170203231929_create_groups.rb +17 -0
  19. data/db/migrate/20170204001405_create_trusted_delegates.rb +13 -0
  20. data/db/schema.rb +95 -0
  21. data/lib/authify/api.rb +51 -0
  22. data/lib/authify/api/controllers/api_key.rb +36 -0
  23. data/lib/authify/api/controllers/group.rb +40 -0
  24. data/lib/authify/api/controllers/organization.rb +48 -0
  25. data/lib/authify/api/controllers/user.rb +72 -0
  26. data/lib/authify/api/helpers/api_user.rb +30 -0
  27. data/lib/authify/api/helpers/jwt_encryption.rb +42 -0
  28. data/lib/authify/api/jsonapi_utils.rb +12 -0
  29. data/lib/authify/api/models/api_key.rb +44 -0
  30. data/lib/authify/api/models/group.rb +17 -0
  31. data/lib/authify/api/models/identity.rb +14 -0
  32. data/lib/authify/api/models/organization.rb +26 -0
  33. data/lib/authify/api/models/organization_membership.rb +16 -0
  34. data/lib/authify/api/models/trusted_delegate.rb +44 -0
  35. data/lib/authify/api/models/user.rb +73 -0
  36. data/lib/authify/api/serializers/api_key_serializer.rb +13 -0
  37. data/lib/authify/api/serializers/group_serializer.rb +15 -0
  38. data/lib/authify/api/serializers/organization_serializer.rb +15 -0
  39. data/lib/authify/api/serializers/user_serializer.rb +17 -0
  40. data/lib/authify/api/service.rb +11 -0
  41. data/lib/authify/api/services/api.rb +58 -0
  42. data/lib/authify/api/services/jwt_provider.rb +61 -0
  43. data/lib/authify/api/version.rb +9 -0
  44. metadata +324 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8444210be1f0a6945d07167d9424740a45ddd019
4
+ data.tar.gz: 2c9808f213e1fcc92ba1b986ea44f2d89bbee85f
5
+ SHA512:
6
+ metadata.gz: fab21a5eb9af6454aaa745647fea348024d683419ea5444a6900388d13fc65b8a7b5d9d4792bfa307690950726c2bffb66fe9a225a815302e053ab13e359d4da
7
+ data.tar.gz: 42541d8379ac40e543b070fe225e4c5a88fd6c85232581dc9de606bb28fcc528dfbbfce65182c0d82862df449a38676557d823b818284663d014b216157301b9
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,23 @@
1
+ Metrics/LineLength:
2
+ Max: 100
3
+
4
+ Metrics/ClassLength:
5
+ Max: 150
6
+
7
+ Metrics/AbcSize:
8
+ Max: 22
9
+
10
+ Metrics/MethodLength:
11
+ Max: 20
12
+
13
+ Metrics/CyclomaticComplexity:
14
+ Max: 10
15
+
16
+ BlockLength:
17
+ Exclude:
18
+ - '*.gemspec'
19
+ - 'lib/authify/api/controllers/*.rb'
20
+
21
+ AllCops:
22
+ Exclude:
23
+ - 'db/schema.rb'
@@ -0,0 +1,13 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
6
+ deploy:
7
+ provider: rubygems
8
+ api_key:
9
+ secure: evFBlOvyjBT71e1FYTtYn6UZ+Q/KW2wPx1rXqgb5H6YBQxPFTjZfAOZ0y1xbYEueUk1qrYuCSlMs8MT7KCzh5oF0KDnhYGKZoRHA/LjbBwqC0hGdePr6oMX6pb68C80wFsCBMPEYfiHupz7x8H/38Xh8zpwpdiQj/MvWnyVwN8x7iZJjAe/Naw5vful2YLdGVvpnqWWdTNsZq2zOdrMDyOUNuPhJawMWomURcw8MBlSR18HJtjh2a2Qi12CZ+mdA2v593IgbxFY6EjHgdpZJuotu+PsjDNaHnRdyGs5+m5pyCsCEUL0B8gmTi8B2apcz1Cxg/sDPUIZGlgIrYhTffmqr1aHIx3xGgoSofkv1k72HL7gDQNkbEyqLuRp9jkcfyYSLdYpq7Vy7uMrDDer77zXHxCcwXDURsWqoBns69ohPzyGIIpKsxCNgVD6DfJF/sXzcGReCn/TS9lW4bzTrWJ8AnSX7e/EXCJoBMy0FPJFDs3mpUShnQdssEH5w2CazJTloe4rZSIq4/eL+pQCtdMNNUi7T/F1dHrRzYcTkWTWQZX3DhZLKXzNu6etun8dzOQ6/2Hb+owwExE9/msbSOeK54AZE21ODKD7+5+qoKIG3CVuGdDE7JPtCjYPkXnOm9Zvo2Rcb30sbNqg+opgwIedVLxDy+PAzP6eUZf0y5bk=
10
+ gem: authify-api
11
+ on:
12
+ tags: true
13
+ repo: knuedge/authify-api
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in authify-api.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 KnuEdge
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Authify::API
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/authify/api`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'authify-api'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install authify-api
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/knuedge/authify-api.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,38 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+ require 'sinatra/activerecord/rake'
5
+
6
+ namespace :db do
7
+ task :load_config do
8
+ require 'authify/api'
9
+ end
10
+ end
11
+
12
+ RSpec::Core::RakeTask.new(:spec)
13
+ RuboCop::RakeTask.new(:rubocop)
14
+
15
+ task default: [:spec, :rubocop]
16
+
17
+ desc 'Start the demo using `rackup`'
18
+ task :start do
19
+ exec 'rackup config.ru'
20
+ end
21
+
22
+ namespace :delegate do
23
+ desc 'Add a Trusted Delegate'
24
+ task :add, [:name] do |_t, args|
25
+ require 'authify/api'
26
+ td = Authify::API::Models::TrustedDelegate.new(
27
+ name: args[:name],
28
+ access_key: Authify::API::Models::TrustedDelegate.generate_access_key
29
+ )
30
+ td.set_secret!
31
+ if td.save
32
+ p(access: td.access_key, secret: td.secret_key)
33
+ else
34
+ puts 'Failed to save Trusted Delegate'
35
+ exit 1
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,45 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'authify/api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'authify-api'
8
+ spec.version = Authify::API::VERSION
9
+ spec.authors = ['Jonathan Gnagy']
10
+ spec.email = ['jgnagy@knuedge.com']
11
+
12
+ spec.summary = 'Authify API Server library'
13
+ spec.homepage = 'https://github.com/knuedge/authify-api'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.required_ruby_version = '~> 2.0'
24
+
25
+ spec.add_runtime_dependency 'authify-core'
26
+ spec.add_runtime_dependency 'authify-middleware'
27
+ spec.add_runtime_dependency 'connection_pool', '~> 2.2'
28
+ spec.add_runtime_dependency 'sinatra', '~> 1.4'
29
+ spec.add_runtime_dependency 'sinatra-activerecord', '~> 2.0'
30
+ spec.add_runtime_dependency 'moneta', '~> 0.8'
31
+ # spec.add_runtime_dependency 'omniauth', '~> 1.3'
32
+ # spec.add_runtime_dependency 'omniauth-github', '~> 1.2'
33
+ spec.add_runtime_dependency 'mysql2', '~> 0.4'
34
+ spec.add_runtime_dependency 'jsonapi-serializers', '~> 0.16'
35
+ spec.add_runtime_dependency 'sinja', '~> 1.2'
36
+ spec.add_runtime_dependency 'puma', '~> 3.7'
37
+
38
+ spec.add_development_dependency 'bundler', '~> 1.12'
39
+ spec.add_development_dependency 'rake', '~> 10.0'
40
+ spec.add_development_dependency 'rspec', '~> 3.1'
41
+ spec.add_development_dependency 'rubocop', '~> 0.35'
42
+ spec.add_development_dependency 'yard', '~> 0.8'
43
+ spec.add_development_dependency 'travis', '~> 1.8'
44
+ spec.add_development_dependency 'simplecov', '~> 0.13'
45
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'authify/api'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,9 @@
1
+ #\ -s puma
2
+
3
+ require 'authify/api'
4
+
5
+ use Rack::ShowExceptions
6
+
7
+ run Rack::URLMap.new \
8
+ '/' => Authify::API::Services::API.new,
9
+ '/jwt' => Authify::API::Services::JWTProvider.new
@@ -0,0 +1,12 @@
1
+ # Creates the users table
2
+ class CreateUsers < ActiveRecord::Migration[5.0]
3
+ def change
4
+ create_table :users do |t|
5
+ t.string :email, index: true
6
+ t.text :password_digest
7
+ t.string :full_name
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # Creates the api_keys table
2
+ class CreateApiKeys < ActiveRecord::Migration[5.0]
3
+ def change
4
+ create_table :api_keys do |t|
5
+ t.references :user, index: true
6
+ t.string :access_key, index: true
7
+ t.text :secret_key_digest
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # Creates the identities table
2
+ class CreateIdentities < ActiveRecord::Migration[5.0]
3
+ def change
4
+ create_table :identities do |t|
5
+ t.references :user, index: true
6
+ t.string :provider, index: true
7
+ t.string :uid, index: true
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,22 @@
1
+ # Creates the organizations table and a join table
2
+ class CreateOrganizationsAndOrganizationMemberships < ActiveRecord::Migration[5.0]
3
+ def change
4
+ create_table :organizations do |t|
5
+ t.string :name, index: true
6
+ t.string :public_email
7
+ t.string :gravatar_email
8
+ t.string :billing_email
9
+ t.text :description
10
+ t.string :url
11
+ t.string :location
12
+
13
+ t.timestamps
14
+ end
15
+
16
+ create_table :organization_memberships do |t|
17
+ t.belongs_to :organization, index: true
18
+ t.belongs_to :user, index: true
19
+ t.boolean :admin, index: true, default: false
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,17 @@
1
+ # Creates the groups table and a join table
2
+ class CreateGroups < ActiveRecord::Migration[5.0]
3
+ def change
4
+ create_table :groups do |t|
5
+ t.belongs_to :organization, index: true
6
+ t.string :name, index: true
7
+ t.text :description
8
+
9
+ t.timestamps
10
+ end
11
+
12
+ create_table :groups_users, id: false do |t|
13
+ t.belongs_to :group, index: true
14
+ t.belongs_to :user, index: true
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ # Creates the trusted_delegates table
2
+ class CreateTrustedDelegates < ActiveRecord::Migration[5.0]
3
+ def change
4
+ create_table :trusted_delegates do |t|
5
+ t.string :name, index: true
6
+ t.string :access_key, index: true
7
+ t.text :secret_key_digest
8
+ t.text :description
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,95 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # Note that this schema.rb definition is the authoritative source for your
6
+ # database schema. If you need to create the application database on another
7
+ # system, you should be using db:schema:load, not running all the migrations
8
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
10
+ #
11
+ # It's strongly recommended that you check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(version: 20170204001405) do
14
+
15
+ create_table "api_keys", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
16
+ t.integer "user_id"
17
+ t.string "access_key"
18
+ t.text "secret_key_digest", limit: 65535
19
+ t.datetime "created_at", null: false
20
+ t.datetime "updated_at", null: false
21
+ t.index ["access_key"], name: "index_api_keys_on_access_key", using: :btree
22
+ t.index ["user_id"], name: "index_api_keys_on_user_id", using: :btree
23
+ end
24
+
25
+ create_table "groups", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
26
+ t.integer "organization_id"
27
+ t.string "name"
28
+ t.text "description", limit: 65535
29
+ t.datetime "created_at", null: false
30
+ t.datetime "updated_at", null: false
31
+ t.index ["name"], name: "index_groups_on_name", using: :btree
32
+ t.index ["organization_id"], name: "index_groups_on_organization_id", using: :btree
33
+ end
34
+
35
+ create_table "groups_users", id: false, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
36
+ t.integer "group_id"
37
+ t.integer "user_id"
38
+ t.index ["group_id"], name: "index_groups_users_on_group_id", using: :btree
39
+ t.index ["user_id"], name: "index_groups_users_on_user_id", using: :btree
40
+ end
41
+
42
+ create_table "identities", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
43
+ t.integer "user_id"
44
+ t.string "provider"
45
+ t.string "uid"
46
+ t.datetime "created_at", null: false
47
+ t.datetime "updated_at", null: false
48
+ t.index ["provider"], name: "index_identities_on_provider", using: :btree
49
+ t.index ["uid"], name: "index_identities_on_uid", using: :btree
50
+ t.index ["user_id"], name: "index_identities_on_user_id", using: :btree
51
+ end
52
+
53
+ create_table "organization_memberships", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
54
+ t.integer "organization_id"
55
+ t.integer "user_id"
56
+ t.boolean "admin", default: false
57
+ t.index ["admin"], name: "index_organization_memberships_on_admin", using: :btree
58
+ t.index ["organization_id"], name: "index_organization_memberships_on_organization_id", using: :btree
59
+ t.index ["user_id"], name: "index_organization_memberships_on_user_id", using: :btree
60
+ end
61
+
62
+ create_table "organizations", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
63
+ t.string "name"
64
+ t.string "public_email"
65
+ t.string "gravatar_email"
66
+ t.string "billing_email"
67
+ t.text "description", limit: 65535
68
+ t.string "url"
69
+ t.string "location"
70
+ t.datetime "created_at", null: false
71
+ t.datetime "updated_at", null: false
72
+ t.index ["name"], name: "index_organizations_on_name", using: :btree
73
+ end
74
+
75
+ create_table "trusted_delegates", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
76
+ t.string "name"
77
+ t.string "access_key"
78
+ t.text "secret_key_digest", limit: 65535
79
+ t.text "description", limit: 65535
80
+ t.datetime "created_at", null: false
81
+ t.datetime "updated_at", null: false
82
+ t.index ["access_key"], name: "index_trusted_delegates_on_access_key", using: :btree
83
+ t.index ["name"], name: "index_trusted_delegates_on_name", using: :btree
84
+ end
85
+
86
+ create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
87
+ t.string "email"
88
+ t.text "password_digest", limit: 65535
89
+ t.string "full_name"
90
+ t.datetime "created_at", null: false
91
+ t.datetime "updated_at", null: false
92
+ t.index ["email"], name: "index_users_on_email", using: :btree
93
+ end
94
+
95
+ end