osso 0.0.3.3 → 0.0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.buildkite/pipeline.yml +4 -1
- data/.gitignore +1 -1
- data/.rubocop.yml +1 -2
- data/Gemfile.lock +3 -1
- data/bin/console +4 -3
- data/config/database.yml +2 -2
- data/{lib/osso/db → db}/schema.rb +7 -15
- data/lib/osso.rb +2 -0
- data/lib/osso/db/migrate/20200328143305_create_identity_providers.rb +12 -0
- data/lib/osso/db/migrate/20200411184535_add_provider_id_to_users.rb +2 -2
- data/lib/osso/db/migrate/20200411192645_create_enterprise_accounts.rb +1 -1
- data/lib/osso/db/migrate/20200502135008_add_oauth_client_id_to_enterprise_accounts_and_identity_providers.rb +6 -0
- data/lib/osso/db/migrate/20200714223226_add_identity_provider_service_enum.rb +17 -0
- data/lib/osso/db/migrate/20200715154211_rename_idp_fields_on_identity_provider_to_sso.rb +6 -0
- data/lib/osso/db/migrate/20200715205801_add_name_to_enterprise_account.rb +5 -0
- data/lib/osso/db/migrate/20200722230116_add_identity_provider_status_enum_and_use_on_identity_providers.rb +15 -0
- data/lib/osso/graphql/mutation.rb +16 -0
- data/lib/osso/graphql/mutations.rb +12 -0
- data/lib/osso/graphql/mutations/base_mutation.rb +41 -0
- data/lib/osso/graphql/mutations/configure_identity_provider.rb +36 -0
- data/lib/osso/graphql/mutations/create_enterprise_account.rb +25 -0
- data/lib/osso/graphql/mutations/create_identity_provider.rb +30 -0
- data/lib/osso/graphql/mutations/set_identity_provider.rb +27 -0
- data/lib/osso/graphql/query.rb +25 -0
- data/lib/osso/graphql/resolvers.rb +12 -0
- data/lib/osso/graphql/resolvers/enterprise_account.rb +25 -0
- data/lib/osso/graphql/resolvers/enterprise_accounts.rb +17 -0
- data/lib/osso/graphql/resolvers/oauth_clients.rb +15 -0
- data/lib/osso/graphql/schema.rb +46 -0
- data/lib/osso/graphql/types.rb +16 -0
- data/lib/osso/graphql/types/base_enum.rb +10 -0
- data/lib/osso/graphql/types/base_input_object.rb +10 -0
- data/lib/osso/graphql/types/base_object.rb +12 -0
- data/lib/osso/graphql/types/enterprise_account.rb +33 -0
- data/lib/osso/graphql/types/identity_provider.rb +33 -0
- data/lib/osso/graphql/types/identity_provider_service.rb +12 -0
- data/lib/osso/graphql/types/identity_provider_status.rb +14 -0
- data/lib/osso/graphql/types/oauth_client.rb +20 -0
- data/lib/osso/graphql/types/user.rb +17 -0
- data/lib/osso/helpers/auth.rb +53 -49
- data/lib/osso/helpers/helpers.rb +3 -1
- data/lib/osso/lib/app_config.rb +1 -1
- data/lib/osso/lib/route_map.rb +28 -0
- data/lib/osso/models/enterprise_account.rb +4 -4
- data/lib/osso/models/identity_provider.rb +56 -0
- data/lib/osso/models/models.rb +1 -1
- data/lib/osso/models/oauth_client.rb +2 -2
- data/lib/osso/models/saml_provider.rb +13 -16
- data/lib/osso/models/saml_providers/azure_saml_provider.rb +2 -2
- data/lib/osso/models/saml_providers/okta_saml_provider.rb +1 -1
- data/lib/osso/models/user.rb +3 -3
- data/lib/osso/routes/admin.rb +18 -19
- data/lib/osso/routes/auth.rb +30 -27
- data/lib/osso/routes/oauth.rb +50 -44
- data/lib/osso/version.rb +1 -1
- data/osso-rb.gemspec +3 -3
- data/spec/factories/enterprise_account.rb +5 -4
- data/spec/factories/identity_providers.rb +49 -0
- data/spec/factories/user.rb +1 -1
- data/spec/graphql/mutations/configure_identity_provider_spec.rb +75 -0
- data/spec/graphql/mutations/create_enterprise_account_spec.rb +68 -0
- data/spec/graphql/mutations/create_identity_provider_spec.rb +104 -0
- data/spec/graphql/query/enterprise_account_spec.rb +68 -0
- data/spec/graphql/query/enterprise_accounts_spec.rb +44 -0
- data/spec/graphql/query/identity_provider_spec.rb +65 -0
- data/spec/graphql/query/oauth_clients_account_spec.rb +48 -0
- data/spec/models/azure_saml_provider_spec.rb +14 -14
- data/spec/models/identity_provider_spec.rb +17 -0
- data/spec/models/okta_saml_provider_spec.rb +15 -15
- data/spec/routes/admin_spec.rb +3 -0
- data/spec/routes/auth_spec.rb +9 -9
- data/spec/routes/oauth_spec.rb +1 -1
- data/spec/spec_helper.rb +8 -5
- data/spec/support/spec_app.rb +9 -0
- data/spec/support/views/admin.erb +5 -0
- metadata +60 -12
- data/lib/osso/db/migrate/20200411144528_create_saml_providers.rb +0 -13
- data/lib/osso/db/migrate/20200413153029_add_oauth_client_reference_to_saml_providers.rb +0 -5
- data/lib/osso/db/migrate/20200501203026_drop_null_constraints_from_saml_provider.rb +0 -7
- data/lib/osso/db/migrate/20200501204047_drop_acs_url.rb +0 -5
- data/lib/osso/db/migrate/20200502135008_add_oauth_client_id_to_enterprise_account.rb +0 -5
- data/lib/osso/db/migrate/20200601131227_drop_null_constraint_from_saml_providers_provider.rb +0 -7
- data/spec/factories/saml_providers.rb +0 -46
- data/spec/models/saml_provider_spec.rb +0 -31
- data/spec/support/vcr_cassettes/okta_saml_callback.yml +0 -59
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Osso
|
4
|
+
module GraphQL
|
5
|
+
module Resolvers
|
6
|
+
class EnterpriseAccount < ::GraphQL::Schema::Resolver
|
7
|
+
type Types::EnterpriseAccount, null: false
|
8
|
+
|
9
|
+
def resolve(args)
|
10
|
+
return unless admin? || enterprise_authorized?(args[:domain])
|
11
|
+
|
12
|
+
Osso::Models::EnterpriseAccount.find_by(domain: args[:domain])
|
13
|
+
end
|
14
|
+
|
15
|
+
def admin?
|
16
|
+
context[:scope] == :admin
|
17
|
+
end
|
18
|
+
|
19
|
+
def enterprise_authorized?(domain)
|
20
|
+
context[:scope] == domain
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Osso
|
4
|
+
module GraphQL
|
5
|
+
module Resolvers
|
6
|
+
class EnterpriseAccounts < ::GraphQL::Schema::Resolver
|
7
|
+
type [Types::EnterpriseAccount], null: true
|
8
|
+
|
9
|
+
def resolve
|
10
|
+
return Osso::Models::EnterpriseAccount.all if context[:scope] == :admin
|
11
|
+
|
12
|
+
Array(Osso::Models::EnterpriseAccount.find_by(domain: context[:scope]))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Osso
|
4
|
+
module GraphQL
|
5
|
+
module Resolvers
|
6
|
+
class OAuthClients < ::GraphQL::Schema::Resolver
|
7
|
+
type [Types::OAuthClient], null: true
|
8
|
+
|
9
|
+
def resolve
|
10
|
+
return Osso::Models::OauthClient.all if context[:scope] == :admin
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'graphql'
|
4
|
+
require_relative 'types'
|
5
|
+
require_relative 'resolvers'
|
6
|
+
require_relative 'mutation'
|
7
|
+
require_relative 'query'
|
8
|
+
|
9
|
+
GraphQL::Relay::BaseConnection.register_connection_implementation(
|
10
|
+
ActiveRecord::Relation,
|
11
|
+
GraphQL::Relay::RelationConnection,
|
12
|
+
)
|
13
|
+
|
14
|
+
module Osso
|
15
|
+
module GraphQL
|
16
|
+
class Schema < ::GraphQL::Schema
|
17
|
+
use ::GraphQL::Pagination::Connections
|
18
|
+
query Types::QueryType
|
19
|
+
mutation Types::MutationType
|
20
|
+
|
21
|
+
def self.id_from_object(object, _type_definition = nil, _query_ctx = nil)
|
22
|
+
GraphQL::Schema::UniqueWithinType.encode(object.class.name, object.id)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.object_from_id(id, _query_ctx = nil)
|
26
|
+
class_name, item_id = GraphQL::Schema::UniqueWithinType.decode(id)
|
27
|
+
Object.const_get(class_name).find(item_id)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.resolve_type(_type, obj, _ctx)
|
31
|
+
case obj
|
32
|
+
when Osso::Models::EnterpriseAccount
|
33
|
+
Types::EnterpriseAccount
|
34
|
+
when Osso::Models::IdentityProvider
|
35
|
+
Types::IdentityProvider
|
36
|
+
else
|
37
|
+
raise("Unexpected object: #{obj}")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.unauthorized_object(error)
|
42
|
+
raise ::GraphQL::ExecutionError, "An object of type #{error.type.graphql_name} was hidden due to permissions"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Osso
|
4
|
+
module Types
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
require_relative 'types/base_object'
|
9
|
+
require_relative 'types/base_enum'
|
10
|
+
require_relative 'types/base_input_object'
|
11
|
+
require_relative 'types/identity_provider_service'
|
12
|
+
require_relative 'types/identity_provider_status'
|
13
|
+
require_relative 'types/identity_provider'
|
14
|
+
require_relative 'types/enterprise_account'
|
15
|
+
require_relative 'types/oauth_client'
|
16
|
+
require_relative 'types/user'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'graphql'
|
4
|
+
|
5
|
+
module Osso
|
6
|
+
module GraphQL
|
7
|
+
module Types
|
8
|
+
class EnterpriseAccount < Types::BaseObject
|
9
|
+
description 'An Account for a company that wishes to use SAML via Osso'
|
10
|
+
implements ::GraphQL::Types::Relay::Node
|
11
|
+
|
12
|
+
global_id_field :gid
|
13
|
+
field :id, ID, null: false
|
14
|
+
field :name, String, null: false
|
15
|
+
field :domain, String, null: false
|
16
|
+
field :identity_providers, [Types::IdentityProvider], null: true
|
17
|
+
field :status, String, null: false
|
18
|
+
|
19
|
+
def status
|
20
|
+
'active'
|
21
|
+
end
|
22
|
+
|
23
|
+
def identity_providers
|
24
|
+
object.identity_providers
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.authorized?(object, context)
|
28
|
+
super && (context[:scope] == :admin || object.domain == context[:scope])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'graphql'
|
4
|
+
|
5
|
+
module Osso
|
6
|
+
module GraphQL
|
7
|
+
module Types
|
8
|
+
class IdentityProvider < Types::BaseObject
|
9
|
+
description 'Represents a SAML based IDP instance for an EnterpriseAccount'
|
10
|
+
implements ::GraphQL::Types::Relay::Node
|
11
|
+
|
12
|
+
global_id_field :gid
|
13
|
+
field :id, ID, null: false
|
14
|
+
field :enterprise_account_id, ID, null: false
|
15
|
+
field :service, Types::IdentityProviderService, null: true
|
16
|
+
field :domain, String, null: false
|
17
|
+
field :acs_url, String, null: false
|
18
|
+
field :sso_url, String, null: true
|
19
|
+
field :sso_cert, String, null: true
|
20
|
+
field :status, Types::IdentityProviderStatus, null: false
|
21
|
+
field :documentation_pdf_url, String, null: true
|
22
|
+
|
23
|
+
def documentation_pdf_url
|
24
|
+
ENV['BASE_URL'] + '/identity_provider/documentation/' + @object.id
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.authorized?(object, context)
|
28
|
+
super && (context[:scope] == :admin || object.domain == context[:scope])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Osso
|
4
|
+
module GraphQL
|
5
|
+
module Types
|
6
|
+
class IdentityProviderService < BaseEnum
|
7
|
+
value('AZURE', 'Microsoft Azure Identity Provider', value: 'Osso::Models::AzureSamlProvider')
|
8
|
+
value('OKTA', 'Okta Identity Provider', value: 'Osso::Models::OktaSamlProvider')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Osso
|
4
|
+
module GraphQL
|
5
|
+
module Types
|
6
|
+
class IdentityProviderStatus < BaseEnum
|
7
|
+
value('Pending', value: 'PENDING')
|
8
|
+
value('Configured', value: 'CONFIGURED')
|
9
|
+
value('Active', value: 'ACTIVE')
|
10
|
+
value('Error', value: 'ERROR')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'graphql'
|
4
|
+
|
5
|
+
module Osso
|
6
|
+
module GraphQL
|
7
|
+
module Types
|
8
|
+
class OAuthClient < Types::BaseObject
|
9
|
+
description 'An OAuth client used to consume Osso SAML users'
|
10
|
+
implements ::GraphQL::Types::Relay::Node
|
11
|
+
|
12
|
+
global_id_field :gid
|
13
|
+
field :id, ID, null: false
|
14
|
+
field :name, String, null: false
|
15
|
+
field :client_id, String, null: false
|
16
|
+
field :client_secret, String, null: false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'graphql'
|
4
|
+
require_relative 'base_object'
|
5
|
+
|
6
|
+
module Osso
|
7
|
+
module GraphQL
|
8
|
+
module Types
|
9
|
+
class User < Types::BaseObject
|
10
|
+
description 'A User of the application'
|
11
|
+
|
12
|
+
field :id, ID, null: false
|
13
|
+
field :name, String, null: true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/osso/helpers/auth.rb
CHANGED
@@ -1,67 +1,71 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
def enterprise_protected!(domain = nil)
|
8
|
-
return if admin_authorized?
|
9
|
-
return if enterprise_authorized?(domain)
|
10
|
-
|
11
|
-
redirect ENV['JWT_URL']
|
12
|
-
end
|
3
|
+
module Osso
|
4
|
+
module Helpers
|
5
|
+
module Auth
|
6
|
+
attr_accessor :current_scope
|
13
7
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
ENV['JWT_HMAC_SECRET'],
|
18
|
-
true,
|
19
|
-
{ algorithm: 'HS256' },
|
20
|
-
)
|
8
|
+
def enterprise_protected!(domain = nil)
|
9
|
+
return if admin_authorized?
|
10
|
+
return if enterprise_authorized?(domain)
|
21
11
|
|
22
|
-
|
12
|
+
halt 401 if request.post?
|
23
13
|
|
24
|
-
|
25
|
-
|
26
|
-
false
|
27
|
-
end
|
14
|
+
redirect ENV['JWT_URL']
|
15
|
+
end
|
28
16
|
|
29
|
-
|
30
|
-
|
17
|
+
def enterprise_authorized?(_domain)
|
18
|
+
payload, _args = JWT.decode(
|
19
|
+
token,
|
20
|
+
ENV['JWT_HMAC_SECRET'],
|
21
|
+
true,
|
22
|
+
{ algorithm: 'HS256' },
|
23
|
+
)
|
31
24
|
|
32
|
-
|
33
|
-
end
|
25
|
+
@current_scope = payload['scope']
|
34
26
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
ENV['JWT_HMAC_SECRET'],
|
39
|
-
true,
|
40
|
-
{ algorithm: 'HS256' },
|
41
|
-
)
|
42
|
-
|
43
|
-
if payload['scope'] == 'admin'
|
44
|
-
@current_scope = :admin
|
45
|
-
return true
|
27
|
+
true
|
28
|
+
rescue JWT::DecodeError
|
29
|
+
false
|
46
30
|
end
|
47
31
|
|
48
|
-
|
49
|
-
|
50
|
-
false
|
51
|
-
end
|
32
|
+
def admin_protected!
|
33
|
+
return if admin_authorized?
|
52
34
|
|
53
|
-
|
54
|
-
|
55
|
-
end
|
35
|
+
redirect ENV['JWT_URL']
|
36
|
+
end
|
56
37
|
|
57
|
-
|
58
|
-
|
38
|
+
def admin_authorized?
|
39
|
+
payload, _args = JWT.decode(
|
40
|
+
token,
|
41
|
+
ENV['JWT_HMAC_SECRET'],
|
42
|
+
true,
|
43
|
+
{ algorithm: 'HS256' },
|
44
|
+
)
|
59
45
|
|
60
|
-
|
46
|
+
if payload['scope'] == 'admin'
|
47
|
+
@current_scope = :admin
|
48
|
+
return true
|
49
|
+
end
|
61
50
|
|
62
|
-
|
51
|
+
false
|
52
|
+
rescue JWT::DecodeError
|
53
|
+
false
|
54
|
+
end
|
55
|
+
|
56
|
+
def token
|
57
|
+
request.env['admin_token'] || session['admin_token'] || request['admin_token']
|
58
|
+
end
|
59
|
+
|
60
|
+
def chomp_token
|
61
|
+
return unless request['admin_token'].present?
|
63
62
|
|
64
|
-
|
63
|
+
session['admin_token'] = request['admin_token']
|
64
|
+
|
65
|
+
return if request.post?
|
66
|
+
|
67
|
+
redirect request.path
|
68
|
+
end
|
65
69
|
end
|
66
70
|
end
|
67
71
|
end
|