apple_id-forestv8_compatibility 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/FUNDING.yml +3 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +10 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/Rakefile +19 -0
- data/VERSION +1 -0
- data/apple_id.gemspec +30 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/apple_id/access_token.rb +11 -0
- data/lib/apple_id/api/user_migration.rb +36 -0
- data/lib/apple_id/client.rb +57 -0
- data/lib/apple_id/event_token/event.rb +44 -0
- data/lib/apple_id/event_token.rb +62 -0
- data/lib/apple_id/id_token/real_user_status.rb +27 -0
- data/lib/apple_id/id_token.rb +103 -0
- data/lib/apple_id/jwks.rb +14 -0
- data/lib/apple_id.rb +63 -0
- metadata +191 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8f6483b72e614f1858924b09c40c618546565213e96d1f52488df2b89b6cc243
|
4
|
+
data.tar.gz: fe9139d5bb728bcb81b9d21c87f84dd5916e3c0c9b4bf0a29c4d65766f1f5a4d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dcf305b072fddb6e10303a577a6e552054e1d24335b21f348fb07110b2fc403cb54e184c92025e2240f2268e98fa00694b75d81385ccee50b00e377d1c6bc27e
|
7
|
+
data.tar.gz: 4f43d54491c74f6fe27611d904a037fb402ea37ec056b535b7c7d7bb4878332e07c85f0f4e870a98bcc16f28fa5a492c5ce50137dd7774a26faa2c0f8211bcc8
|
data/.github/FUNDING.yml
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at nov@matake.jp. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 nov
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# AppleID
|
2
|
+
|
3
|
+
"Sign-in with Apple" is an implementation of OpenID Connect with small custom features.
|
4
|
+
|
5
|
+
This gem handles these Apple custom features.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'apple_id'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install apple_id
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
There is [a sample rails app](https://github.com/nov/signin-with-apple) running at [signin-with-apple.herokuapp.com](https://signin-with-apple.herokuapp.com).
|
26
|
+
|
27
|
+
If you run script in your terminal only, [do like this](https://gist.github.com/nov/993a303aa6badd8447f7b96fb952088e).
|
28
|
+
|
29
|
+
For more details, see [AppleID Wiki](https://github.com/nov/apple_id/wiki).
|
30
|
+
|
31
|
+
## Development
|
32
|
+
|
33
|
+
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.
|
34
|
+
|
35
|
+
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).
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nov/apple_id. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
44
|
+
|
45
|
+
## Code of Conduct
|
46
|
+
|
47
|
+
Everyone interacting in the AppleID project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/nov/apple_id/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
namespace :coverage do
|
8
|
+
desc 'Open coverage report'
|
9
|
+
task :report do
|
10
|
+
require 'simplecov'
|
11
|
+
`open "#{File.join SimpleCov.coverage_path, 'index.html'}"`
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
task :spec do
|
16
|
+
Rake::Task[:'coverage:report'].invoke unless ENV['TRAVIS_RUBY_VERSION']
|
17
|
+
end
|
18
|
+
|
19
|
+
task :default => :spec
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.5.3
|
data/apple_id.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = 'apple_id-forestv8_compatibility'
|
3
|
+
spec.version = File.read('VERSION')
|
4
|
+
spec.authors = ['nov']
|
5
|
+
spec.email = ['nov@matake.jp']
|
6
|
+
|
7
|
+
spec.summary = %q{Sign-in with Apple Backend}
|
8
|
+
spec.description = %q{Sign-in with Apple backend library in Ruby.}
|
9
|
+
spec.homepage = 'https://github.com/nov/apple_id'
|
10
|
+
spec.license = 'MIT'
|
11
|
+
|
12
|
+
# Specify which files should be added to the gem when it is released.
|
13
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
14
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
15
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
end
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'json-jwt', '~> 1.15.2'
|
22
|
+
spec.add_runtime_dependency 'rack-oauth2', '~> 1.21.2'
|
23
|
+
spec.add_runtime_dependency 'openid_connect', '= 1.4.2'
|
24
|
+
spec.add_development_dependency 'bundler'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
spec.add_development_dependency 'rspec'
|
27
|
+
spec.add_development_dependency 'rspec-its'
|
28
|
+
spec.add_development_dependency 'webmock'
|
29
|
+
spec.add_development_dependency 'simplecov'
|
30
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "apple_id"
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
module AppleID
|
2
|
+
class AccessToken < OpenIDConnect::AccessToken
|
3
|
+
undef_required_attributes :client
|
4
|
+
attr_optional :client
|
5
|
+
|
6
|
+
def initialize(access_token, attributes = {})
|
7
|
+
super attributes.merge(access_token: access_token)
|
8
|
+
self.id_token = IdToken.decode(id_token) if id_token.present?
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module AppleID
|
2
|
+
module API
|
3
|
+
module UserMigration
|
4
|
+
def transfer_from!(transfer_sub:)
|
5
|
+
resource_request do
|
6
|
+
post(
|
7
|
+
user_migration_endpoint,
|
8
|
+
transfer_sub: transfer_sub,
|
9
|
+
client_id: client.identifier,
|
10
|
+
client_secret: client.secret
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def transfer_to!(sub:, target:)
|
16
|
+
resource_request do
|
17
|
+
post(
|
18
|
+
user_migration_endpoint,
|
19
|
+
sub: sub,
|
20
|
+
target: client.team_id,
|
21
|
+
client_id: client.identifier,
|
22
|
+
client_secret: client.secret
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def user_migration_endpoint
|
30
|
+
File.join(ISSUER, '/auth/usermigrationinfo')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
AccessToken.include UserMigration
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module AppleID
|
2
|
+
class Client < OpenIDConnect::Client
|
3
|
+
class Error < Rack::OAuth2::Client::Error; end
|
4
|
+
|
5
|
+
attr_required :team_id, :key_id, :private_key
|
6
|
+
|
7
|
+
def initialize(attributes)
|
8
|
+
attributes_with_default = {
|
9
|
+
authorization_endpoint: File.join(ISSUER, '/auth/authorize'),
|
10
|
+
token_endpoint: File.join(ISSUER, '/auth/token'),
|
11
|
+
revocation_endpoint: File.join(ISSUER, '/auth/revoke'),
|
12
|
+
}.merge(attributes)
|
13
|
+
super attributes_with_default
|
14
|
+
end
|
15
|
+
|
16
|
+
def access_token!(options = {})
|
17
|
+
self.secret = client_secret_jwt
|
18
|
+
super :body, options
|
19
|
+
end
|
20
|
+
|
21
|
+
def revoke!(options = {})
|
22
|
+
self.secret = client_secret_jwt
|
23
|
+
super :body, options
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def client_secret_jwt
|
29
|
+
jwt = JSON::JWT.new(
|
30
|
+
iss: team_id,
|
31
|
+
aud: ISSUER,
|
32
|
+
sub: identifier,
|
33
|
+
iat: Time.now,
|
34
|
+
exp: 1.minutes.from_now
|
35
|
+
)
|
36
|
+
jwt.kid = key_id
|
37
|
+
jwt.sign(private_key)
|
38
|
+
end
|
39
|
+
|
40
|
+
def setup_required_scope(scopes)
|
41
|
+
# NOTE:
|
42
|
+
# openid_connect gem add `openid` scope automatically.
|
43
|
+
# However, it's not required for Sign-in with Apple.
|
44
|
+
scopes
|
45
|
+
end
|
46
|
+
|
47
|
+
def handle_success_response(response)
|
48
|
+
token_hash = JSON.parse(response.body).with_indifferent_access
|
49
|
+
AccessToken.new token_hash.delete(:access_token), token_hash.merge(client: self)
|
50
|
+
end
|
51
|
+
|
52
|
+
def handle_error_response(response)
|
53
|
+
error = JSON.parse(response.body).with_indifferent_access
|
54
|
+
raise Error.new(response.status, error)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module AppleID
|
2
|
+
class EventToken::Event < OpenIDConnect::ConnectObject
|
3
|
+
attr_required :type, :sub, :event_time
|
4
|
+
attr_optional :email, :is_private_email
|
5
|
+
|
6
|
+
module Type
|
7
|
+
EMAIL_ENABLED = 'email-enabled'
|
8
|
+
EMAIL_DISABLED = 'email-disabled'
|
9
|
+
CONSENT_REVOKED = 'consent-revoked'
|
10
|
+
ACCOUNT_DELETED = 'account-delete'
|
11
|
+
end
|
12
|
+
|
13
|
+
def email_enabled?
|
14
|
+
type == Type::EMAIL_ENABLED
|
15
|
+
end
|
16
|
+
|
17
|
+
def email_disabled?
|
18
|
+
type == Type::EMAIL_DISABLED
|
19
|
+
end
|
20
|
+
|
21
|
+
def consent_revoked?
|
22
|
+
type == Type::CONSENT_REVOKED
|
23
|
+
end
|
24
|
+
|
25
|
+
def account_deleted?
|
26
|
+
type == Type::ACCOUNT_DELETED
|
27
|
+
end
|
28
|
+
alias_method :account_delete?, :account_deleted?
|
29
|
+
|
30
|
+
def is_private_email?
|
31
|
+
if is_private_email.is_a? String
|
32
|
+
is_private_email == 'true'
|
33
|
+
else
|
34
|
+
!!is_private_email
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class << self
|
39
|
+
def decode(json_string)
|
40
|
+
new JSON.parse(json_string).with_indifferent_access
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module AppleID
|
2
|
+
class EventToken < OpenIDConnect::ConnectObject
|
3
|
+
class VerificationFailed < Error; end
|
4
|
+
|
5
|
+
attr_required :iss, :aud, :exp, :iat, :jti, :events
|
6
|
+
alias_method :original_jwt, :raw_attributes
|
7
|
+
alias_method :event, :events
|
8
|
+
|
9
|
+
delegate :type, :sub, :event_time, :email_enabled?, :email_disabled?, :consent_revoked?, :account_deleted?, to: :event
|
10
|
+
|
11
|
+
def initialize(attributes = {})
|
12
|
+
super
|
13
|
+
@events = Event.decode attributes[:events]
|
14
|
+
end
|
15
|
+
|
16
|
+
def verify!(verify_signature: true, client: nil)
|
17
|
+
verify_signature! if verify_signature
|
18
|
+
verify_claims! client
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
class << self
|
23
|
+
def decode(jwt_string)
|
24
|
+
new JSON::JWT.decode jwt_string, :skip_verification
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def verify_signature!
|
31
|
+
original_jwt.verify! JWKS.fetch(original_jwt.kid)
|
32
|
+
rescue
|
33
|
+
raise VerificationFailed, 'Signature Verification Failed'
|
34
|
+
end
|
35
|
+
|
36
|
+
def verify_claims!(client)
|
37
|
+
aud = if client.respond_to?(:identifier)
|
38
|
+
client.identifier
|
39
|
+
else
|
40
|
+
client
|
41
|
+
end
|
42
|
+
|
43
|
+
failure_reasons = []
|
44
|
+
if self.iss != ISSUER
|
45
|
+
failure_reasons << :iss
|
46
|
+
end
|
47
|
+
if aud.present? && self.aud != aud
|
48
|
+
failure_reasons << :aud
|
49
|
+
end
|
50
|
+
if Time.now.to_i < iat
|
51
|
+
failure_reasons << :iat
|
52
|
+
end
|
53
|
+
if Time.now.to_i >= exp
|
54
|
+
failure_reasons << :exp
|
55
|
+
end
|
56
|
+
|
57
|
+
if failure_reasons.present?
|
58
|
+
raise VerificationFailed, "Claims Verification Failed at #{failure_reasons}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module AppleID
|
2
|
+
class IdToken::RealUserStatus
|
3
|
+
class UndefinedStatus < StandardError; end
|
4
|
+
|
5
|
+
attr_accessor :value
|
6
|
+
|
7
|
+
STATUSES = [
|
8
|
+
:unsupported,
|
9
|
+
:unknown,
|
10
|
+
:likely_real
|
11
|
+
]
|
12
|
+
|
13
|
+
def initialize(value)
|
14
|
+
self.value = value
|
15
|
+
end
|
16
|
+
|
17
|
+
STATUSES.each do |expected_status|
|
18
|
+
define_method :"#{expected_status}?" do
|
19
|
+
send(:status) == expected_status
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def status
|
24
|
+
STATUSES[value] or raise UndefinedStatus
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module AppleID
|
2
|
+
class IdToken < OpenIDConnect::ResponseObject::IdToken
|
3
|
+
class VerificationFailed < Error; end
|
4
|
+
|
5
|
+
attr_optional :email, :email_verified, :is_private_email, :nonce_supported, :real_user_status
|
6
|
+
attr_accessor :original_jwt_string
|
7
|
+
alias_method :original_jwt, :raw_attributes
|
8
|
+
|
9
|
+
[:email_verified, :is_private_email, :nonce_supported].each do |boolean_claim|
|
10
|
+
define_method :"#{boolean_claim}?" do
|
11
|
+
claim_value = send(boolean_claim)
|
12
|
+
case claim_value
|
13
|
+
when String
|
14
|
+
claim_value == 'true'
|
15
|
+
else
|
16
|
+
!!claim_value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(attributes = {})
|
22
|
+
super
|
23
|
+
unless self.real_user_status.nil?
|
24
|
+
self.real_user_status = RealUserStatus.new(self.real_user_status)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def verify!(verify_signature: true, client: nil, nonce: nil, state: nil, access_token: nil, code: nil)
|
29
|
+
verify_signature! if verify_signature
|
30
|
+
verify_claims! client, nonce, state, access_token, code
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
class << self
|
35
|
+
def decode(jwt_string)
|
36
|
+
id_token = super jwt_string, :skip_verification
|
37
|
+
id_token.original_jwt_string = jwt_string
|
38
|
+
id_token
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def verify_signature!
|
45
|
+
original_jwt.verify! JWKS.fetch(original_jwt.kid)
|
46
|
+
rescue
|
47
|
+
raise VerificationFailed, 'Signature Verification Failed'
|
48
|
+
end
|
49
|
+
|
50
|
+
def verify_claims!(client, nonce, state, access_token, code)
|
51
|
+
aud = if client.respond_to?(:identifier)
|
52
|
+
client.identifier
|
53
|
+
else
|
54
|
+
client
|
55
|
+
end
|
56
|
+
|
57
|
+
hash_length = original_jwt.alg.to_s[2, 3].to_i
|
58
|
+
s_hash = if state.present?
|
59
|
+
left_half_hash_of state, hash_length
|
60
|
+
end
|
61
|
+
at_hash = if access_token.present?
|
62
|
+
left_half_hash_of access_token, hash_length
|
63
|
+
end
|
64
|
+
c_hash = if code.present?
|
65
|
+
left_half_hash_of code, hash_length
|
66
|
+
end
|
67
|
+
|
68
|
+
failure_reasons = []
|
69
|
+
if self.iss != ISSUER
|
70
|
+
failure_reasons << :iss
|
71
|
+
end
|
72
|
+
if aud.present? && self.aud != aud
|
73
|
+
failure_reasons << :aud
|
74
|
+
end
|
75
|
+
if !nonce_supported? && self.nonce.blank?
|
76
|
+
AppleID.logger.warn 'nonce is\'nt supported on this platform'
|
77
|
+
else
|
78
|
+
if nonce.present? && self.nonce != nonce
|
79
|
+
failure_reasons << :nonce
|
80
|
+
end
|
81
|
+
end
|
82
|
+
if s_hash.present? && self.s_hash != s_hash
|
83
|
+
failure_reasons << :s_hash
|
84
|
+
end
|
85
|
+
if at_hash.present? && self.at_hash != at_hash
|
86
|
+
failure_reasons << :at_hash
|
87
|
+
end
|
88
|
+
if c_hash.present? && self.c_hash != c_hash
|
89
|
+
failure_reasons << :c_hash
|
90
|
+
end
|
91
|
+
if Time.now.to_i < iat
|
92
|
+
failure_reasons << :iat
|
93
|
+
end
|
94
|
+
if Time.now.to_i >= exp
|
95
|
+
failure_reasons << :exp
|
96
|
+
end
|
97
|
+
|
98
|
+
if failure_reasons.present?
|
99
|
+
raise VerificationFailed, "Claims Verification Failed at #{failure_reasons}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module AppleID
|
2
|
+
class JWKS < JSON::JWK::Set
|
3
|
+
def self.cache=(cache)
|
4
|
+
JSON::JWK::Set::Fetcher.cache = cache
|
5
|
+
end
|
6
|
+
def self.cache
|
7
|
+
JSON::JWK::Set::Fetcher.cache
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.fetch(kid, options = {})
|
11
|
+
JSON::JWK::Set::Fetcher.fetch JWKS_URI, kid: kid, **options
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/apple_id.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'openid_connect'
|
2
|
+
|
3
|
+
module AppleID
|
4
|
+
ISSUER = 'https://appleid.apple.com'
|
5
|
+
JWKS_URI = 'https://appleid.apple.com/auth/keys'
|
6
|
+
|
7
|
+
VERSION = ::File.read(
|
8
|
+
::File.join(::File.dirname(__FILE__), '../VERSION')
|
9
|
+
).chomp
|
10
|
+
|
11
|
+
class Error < StandardError; end
|
12
|
+
|
13
|
+
def self.logger
|
14
|
+
@@logger
|
15
|
+
end
|
16
|
+
def self.logger=(logger)
|
17
|
+
@@logger = logger
|
18
|
+
end
|
19
|
+
self.logger = Logger.new(STDOUT)
|
20
|
+
self.logger.progname = 'AppleID'
|
21
|
+
|
22
|
+
@sub_protocols = [
|
23
|
+
OpenIDConnect
|
24
|
+
]
|
25
|
+
def self.debugging?
|
26
|
+
@@debugging
|
27
|
+
end
|
28
|
+
def self.debugging=(boolean)
|
29
|
+
@sub_protocols.each do |klass|
|
30
|
+
klass.debugging = boolean
|
31
|
+
end
|
32
|
+
@@debugging = boolean
|
33
|
+
end
|
34
|
+
def self.debug!
|
35
|
+
@sub_protocols.each do |klass|
|
36
|
+
klass.debug!
|
37
|
+
end
|
38
|
+
self.debugging = true
|
39
|
+
end
|
40
|
+
def self.debug(&block)
|
41
|
+
sub_protocol_originals = @sub_protocols.inject({}) do |sub_protocol_originals, klass|
|
42
|
+
sub_protocol_originals.merge!(klass => klass.debugging?)
|
43
|
+
end
|
44
|
+
original = self.debugging?
|
45
|
+
debug!
|
46
|
+
yield
|
47
|
+
ensure
|
48
|
+
@sub_protocols.each do |klass|
|
49
|
+
klass.debugging = sub_protocol_originals[klass]
|
50
|
+
end
|
51
|
+
self.debugging = original
|
52
|
+
end
|
53
|
+
self.debugging = false
|
54
|
+
end
|
55
|
+
|
56
|
+
require 'apple_id/client'
|
57
|
+
require 'apple_id/access_token'
|
58
|
+
require 'apple_id/id_token'
|
59
|
+
require 'apple_id/id_token/real_user_status'
|
60
|
+
require 'apple_id/jwks'
|
61
|
+
require 'apple_id/event_token'
|
62
|
+
require 'apple_id/event_token/event'
|
63
|
+
require 'apple_id/api/user_migration'
|
metadata
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: apple_id-forestv8_compatibility
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.5.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- nov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-01-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json-jwt
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.15.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.15.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rack-oauth2
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.21.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.21.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: openid_connect
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.4.2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.4.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
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
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec-its
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: simplecov
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: Sign-in with Apple backend library in Ruby.
|
140
|
+
email:
|
141
|
+
- nov@matake.jp
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".github/FUNDING.yml"
|
147
|
+
- ".gitignore"
|
148
|
+
- ".rspec"
|
149
|
+
- ".travis.yml"
|
150
|
+
- CODE_OF_CONDUCT.md
|
151
|
+
- Gemfile
|
152
|
+
- LICENSE.txt
|
153
|
+
- README.md
|
154
|
+
- Rakefile
|
155
|
+
- VERSION
|
156
|
+
- apple_id.gemspec
|
157
|
+
- bin/console
|
158
|
+
- bin/setup
|
159
|
+
- lib/apple_id.rb
|
160
|
+
- lib/apple_id/access_token.rb
|
161
|
+
- lib/apple_id/api/user_migration.rb
|
162
|
+
- lib/apple_id/client.rb
|
163
|
+
- lib/apple_id/event_token.rb
|
164
|
+
- lib/apple_id/event_token/event.rb
|
165
|
+
- lib/apple_id/id_token.rb
|
166
|
+
- lib/apple_id/id_token/real_user_status.rb
|
167
|
+
- lib/apple_id/jwks.rb
|
168
|
+
homepage: https://github.com/nov/apple_id
|
169
|
+
licenses:
|
170
|
+
- MIT
|
171
|
+
metadata: {}
|
172
|
+
post_install_message:
|
173
|
+
rdoc_options: []
|
174
|
+
require_paths:
|
175
|
+
- lib
|
176
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
|
+
requirements:
|
183
|
+
- - ">="
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '0'
|
186
|
+
requirements: []
|
187
|
+
rubygems_version: 3.1.6
|
188
|
+
signing_key:
|
189
|
+
specification_version: 4
|
190
|
+
summary: Sign-in with Apple Backend
|
191
|
+
test_files: []
|