omniauth-apple-sau226 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c621934826914eb43bfe969de4cf4a30a0100ccf92522e30cc8f5006a958870f
4
- data.tar.gz: 2f4cdfed997ab7b5e4585fa3ed05bc51d48fea117de73c6e7faa41595ca0cbb3
3
+ metadata.gz: 5def05edbb741780cfd044218554788c7055c58354c6af327a7630793a3870bf
4
+ data.tar.gz: 6316e8050837aabeefcd1449dcbd427ac463b7b39189b9e07a06944218ed23f0
5
5
  SHA512:
6
- metadata.gz: 3b32ea123ccc094429ee3ce5ceebaaa9b3e996c3c8875e4fea297f8faca63264d0589976292515db5aa5f40a5907ab4585603bd867ca71df806b4406020d1740
7
- data.tar.gz: 48bf3d81261b4cc2a63be173618c1953e0923168043364b70b856a5604fda2c701d082e2c46bba7454058f24ddca6fbc0ed86a7fb03a8a79b7f7b82557cc2009
6
+ metadata.gz: 39f36c82ffb8c65f8c4b2f2bf991db4957defcb2308beb24e44669283f6e8d9404e88defc31e4556114facd61aafe5eb40f98b9e11754c6787bd962ecf971d95
7
+ data.tar.gz: 99cf9f9758b942750dfc21695a9efa94c905814c6ad729c1eb9edc15033a61145fff5565a65e7474550744d7b0e61b983f0195d480e524ec1240136073bd8944
data/.gitignore CHANGED
@@ -48,3 +48,4 @@ Gemfile.lock
48
48
 
49
49
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
50
  .rvmrc
51
+ .idea
data/README.md CHANGED
@@ -22,9 +22,12 @@ Or install it yourself as:
22
22
 
23
23
  ```ruby
24
24
  Rails.application.config.middleware.use OmniAuth::Builder do
25
- provider :apple, ENV['CLIENT_ID'], ENV['TEAM_ID'], ENV['KEY_ID'], ENV['PRIVATE_KEY'],
25
+ provider :apple, ENV['CLIENT_ID'], '',
26
26
  {
27
27
  scope: 'email name',
28
+ team_id: ENV['TEAM_ID'],
29
+ key_id: ENV['KEY_ID'],
30
+ pem: ENV['PRIVATE_KEY']
28
31
  }
29
32
  end
30
33
  ```
@@ -1,7 +1,7 @@
1
1
  module Omniauth
2
2
  module Apple
3
3
  module Sau226
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
6
6
  end
7
7
  end
@@ -1,24 +1,34 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'omniauth-oauth2'
2
4
 
3
5
  module OmniAuth
4
6
  module Strategies
5
7
  class Apple < OmniAuth::Strategies::OAuth2
6
-
7
- attr_reader :id_token
8
- args %i[client_id team_id key_id pem]
9
-
10
8
  option :name, 'apple'
11
- option :client_options, {
12
- site: 'https://appleid.apple.com',
13
- authorize_url: '/auth/authorize',
14
- token_url: '/auth/token',
15
- response_mode: 'form_post',
16
- }
17
9
 
18
- uid { id_token['sub'] }
10
+ option :client_options,
11
+ site: 'https://appleid.apple.com',
12
+ authorize_url: '/auth/authorize',
13
+ token_url: '/auth/token'
14
+ option :authorize_params,
15
+ response_mode: 'form_post'
16
+
17
+ uid { id_info['sub'] }
19
18
 
20
19
  info do
21
- { email: id_token['email'] }
20
+ {
21
+ sub: id_info['sub'],
22
+ email: email,
23
+ first_name: first_name,
24
+ last_name: last_name
25
+ }
26
+ end
27
+
28
+ extra do
29
+ {
30
+ raw_info: id_info.merge(user_info)
31
+ }
22
32
  end
23
33
 
24
34
  def client
@@ -26,27 +36,47 @@ module OmniAuth
26
36
  end
27
37
 
28
38
  def callback_url
29
- full_host + script_name + callback_path
39
+ options[:redirect_uri] || (full_host + script_name + callback_path)
30
40
  end
31
41
 
32
- def build_access_token
33
- _access_token = super
34
- @id_token = ::JSON::JWT.decode(_access_token.params['id_token'], :skip_verification)
35
- _access_token
42
+ private
43
+
44
+ def id_info
45
+ id_token = request.params['id_token'] || access_token.params['id_token']
46
+ log(:info, "id_token: #{id_token}")
47
+ @id_info ||= ::JWT.decode(id_token, nil, false)[0] # payload after decoding
36
48
  end
37
49
 
38
- private
50
+ def user_info
51
+ return {} unless request.params['user'].present?
52
+
53
+ log(:info, "user_info: #{request.params['user']}")
54
+ @user_info ||= JSON.parse(request.params['user'])
55
+ end
56
+
57
+ def email
58
+ user_info['email'] || id_info['email']
59
+ end
60
+
61
+ def first_name
62
+ user_info.dig('name', 'firstName')
63
+ end
64
+
65
+ def last_name
66
+ user_info.dig('name', 'lastName')
67
+ end
39
68
 
40
69
  def client_secret
41
- jwt = ::JSON::JWT.new(
70
+ payload = {
42
71
  iss: options.team_id,
43
72
  aud: 'https://appleid.apple.com',
44
73
  sub: options.client_id,
45
- iat: (now = Time.respond_to?(:current) ? Time.current : Time.now),
46
- exp: now + 60
47
- )
48
- jwt.kid = options.key_id
49
- jwt.sign(private_key).to_s
74
+ iat: Time.now.to_i,
75
+ exp: Time.now.to_i + 60
76
+ }
77
+ headers = { kid: options.key_id }
78
+
79
+ ::JWT.encode(payload, private_key, 'ES256', headers)
50
80
  end
51
81
 
52
82
  def private_key
@@ -6,12 +6,12 @@ require "omniauth/apple/sau226/version"
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "omniauth-apple-sau226"
8
8
  spec.version = Omniauth::Apple::Sau226::VERSION
9
- spec.authors = ["nhosoya", "sau226"]
10
- spec.email = ["hnhnnhnh@gmail.com"]
9
+ spec.authors = ["nhosoya", "Fabian Jäger", "sau226"]
10
+ spec.email = ["hnhnnhnh@gmail.com", "fabian@mailbutler.io"]
11
11
 
12
- spec.summary = %q{Customized build by sau226 of the omniauth-apple gem}
13
- spec.description = %q{Customized build by sau226 of the omniauth-apple gem}
14
- spec.homepage = "https://github.com/sau226/omniauth-apple"
12
+ spec.summary = %q{sau226's custom build of omniauth-apple}
13
+ spec.description = %q{OmniAuth strategy for Sign In with Apple}
14
+ spec.homepage = "https://github.com/sau226dev/omniauth-apple"
15
15
  spec.license = "MIT"
16
16
 
17
17
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
@@ -37,7 +37,7 @@ Gem::Specification.new do |spec|
37
37
  spec.require_paths = ["lib"]
38
38
 
39
39
  spec.add_dependency 'omniauth-oauth2'
40
- spec.add_dependency 'json-jwt'
40
+ spec.add_dependency 'jwt'
41
41
  spec.add_development_dependency "bundler", "~> 2.0"
42
42
  spec.add_development_dependency "rake", "~> 10.0"
43
43
  end
metadata CHANGED
@@ -1,10 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-apple-sau226
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - nhosoya
8
+ - Fabian Jäger
8
9
  - sau226
9
10
  autorequire:
10
11
  bindir: exe
@@ -26,7 +27,7 @@ dependencies:
26
27
  - !ruby/object:Gem::Version
27
28
  version: '0'
28
29
  - !ruby/object:Gem::Dependency
29
- name: json-jwt
30
+ name: jwt
30
31
  requirement: !ruby/object:Gem::Requirement
31
32
  requirements:
32
33
  - - ">="
@@ -67,9 +68,10 @@ dependencies:
67
68
  - - "~>"
68
69
  - !ruby/object:Gem::Version
69
70
  version: '10.0'
70
- description: Customized build by sau226 of the omniauth-apple gem
71
+ description: OmniAuth strategy for Sign In with Apple
71
72
  email:
72
73
  - hnhnnhnh@gmail.com
74
+ - fabian@mailbutler.io
73
75
  executables: []
74
76
  extensions: []
75
77
  extra_rdoc_files: []
@@ -86,7 +88,7 @@ files:
86
88
  - lib/omniauth/apple/sau226/version.rb
87
89
  - lib/omniauth/strategies/apple.rb
88
90
  - omniauth-apple-sau226.gemspec
89
- homepage: https://github.com/sau226/omniauth-apple
91
+ homepage: https://github.com/sau226dev/omniauth-apple
90
92
  licenses:
91
93
  - MIT
92
94
  metadata: {}
@@ -108,5 +110,5 @@ requirements: []
108
110
  rubygems_version: 3.1.2
109
111
  signing_key:
110
112
  specification_version: 4
111
- summary: Customized build by sau226 of the omniauth-apple gem
113
+ summary: sau226's custom build of omniauth-apple
112
114
  test_files: []