intercode_client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,58 @@
1
+ require 'omniauth-oauth2'
2
+ require 'graphql/client'
3
+ require 'graphql/client/http'
4
+ require 'intercode_client'
5
+
6
+ module OmniAuth
7
+ module Strategies
8
+ class Intercode < OmniAuth::Strategies::OAuth2
9
+ CurrentUserQuery = IntercodeClient::Client.parse <<~GRAPHQL
10
+ query IntercodeClientCurrentUserQuery {
11
+ currentUser {
12
+ id
13
+ first_name
14
+ last_name
15
+ email
16
+ }
17
+ }
18
+ GRAPHQL
19
+
20
+ # Give your strategy a name.
21
+ option :name, 'intercode'
22
+
23
+ # This is where you pass the options you would pass when
24
+ # initializing your consumer from the OAuth gem.
25
+ option :client_options, site: IntercodeClient.intercode_url
26
+
27
+ uid do
28
+ decoded_jwt['user']['id']
29
+ end
30
+
31
+ info do
32
+ {
33
+ first_name: raw_info.data.current_user.first_name,
34
+ last_name: raw_info.data.current_user.last_name,
35
+ email: raw_info.data.current_user.email
36
+ }
37
+ end
38
+
39
+ extra do
40
+ {
41
+ 'access_token' => access_token.token,
42
+ 'raw_info' => raw_info.to_h
43
+ }
44
+ end
45
+
46
+ def raw_info
47
+ @raw_info ||= IntercodeClient::Client.query(
48
+ CurrentUserQuery,
49
+ context: { headers: access_token.headers }
50
+ )
51
+ end
52
+
53
+ def decoded_jwt
54
+ @decoded_jwt ||= IntercodeClient.decode_jwt(access_token.token)
55
+ end
56
+ end
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: intercode_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nat Budin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-08-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: graphql-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json-jwt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: omniauth-oauth2
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - natbudin@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".github/workflows/main.yml"
77
+ - ".gitignore"
78
+ - ".rubocop.yml"
79
+ - CHANGELOG.md
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - intercode_client.gemspec
89
+ - lib/intercode_client.rb
90
+ - lib/intercode_client/version.rb
91
+ - lib/intercode_schema.json
92
+ - lib/omniauth/strategies/intercode.rb
93
+ homepage: https://github.com/neinteractiveliterature/intercode_client
94
+ licenses:
95
+ - MIT
96
+ metadata:
97
+ allowed_push_host: https://rubygems.org
98
+ homepage_uri: https://github.com/neinteractiveliterature/intercode_client
99
+ source_code_uri: https://github.com/neinteractiveliterature/intercode_client
100
+ changelog_uri: https://github.com/neinteractiveliterature/intercode_client
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 2.4.0
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubygems_version: 3.1.6
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: A Ruby client and OmniAuth strategy for Intercode
120
+ test_files: []