sign_in_with_apple_user_migrator 1.0.0 → 1.0.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32bdec7f75c80ec3528d6b13ede6fde69f0235e210686dfd0fb76b49fc624bc1
|
4
|
+
data.tar.gz: eb24fad77153c45ced88544fdc14d62175bfa5e1882c89c139bc9916e70c5041
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 646e350db7c6d8e05afc5709c05c91dd539c9a93237b31ef01a69d7fc1000dfa6cdf092ac200d2ff71b5893d79f50bdf15872340b8df4373463aa76f04265216
|
7
|
+
data.tar.gz: a8f5844ab8ac7f356badd326e5c949a101cb14e8dfb2d19689e1942e23f281c0082f9be5a90e8d603b96f377bb829f035b880b919a09a84e27319bdce9c7f93d
|
@@ -5,107 +5,133 @@ require_relative '../sign_in_with_apple_user_migrator'
|
|
5
5
|
|
6
6
|
module SignInWithAppleUserMigrator
|
7
7
|
class CLI < Thor
|
8
|
+
COMMON_OPTIONS = {
|
9
|
+
client_id: { required: true, desc: 'Client ID' },
|
10
|
+
key_id: { required: true, desc: 'Key ID' },
|
11
|
+
private_key_path: { required: true, desc: 'Private Key Path' },
|
12
|
+
team_id: { required: true, desc: 'Team ID' }
|
13
|
+
}
|
14
|
+
|
8
15
|
desc 'generate_user_transfer_ids', 'Generate user transfer IDs'
|
9
|
-
|
10
|
-
option :key_id, required: true, desc: 'Key ID'
|
11
|
-
option :private_key_path, required: true, desc: 'Private Key Path'
|
12
|
-
option :team_id, required: true, desc: 'Team ID'
|
16
|
+
COMMON_OPTIONS.each { |name, opts| option(name, opts) }
|
13
17
|
option :transfer_user_id_csv_path, required: true, desc: 'Transfer User ID CSV Path'
|
14
18
|
option :target_team_id, required: true, desc: 'Target Team ID'
|
15
19
|
|
16
20
|
def generate_user_transfer_ids
|
17
|
-
|
18
|
-
key_id = options[:key_id]
|
19
|
-
private_key_path = options[:private_key_path]
|
20
|
-
team_id = options[:team_id]
|
21
|
+
token_manager = TokenManager.new(**common_options)
|
21
22
|
transfer_user_id_csv_path = options[:transfer_user_id_csv_path]
|
22
23
|
target_team_id = options[:target_team_id]
|
23
24
|
|
24
|
-
client_secret = SignInWithAppleUserMigrator::ClientSecretGenerator.new(
|
25
|
-
client_id: client_id,
|
26
|
-
key_id: key_id,
|
27
|
-
private_key_path: private_key_path,
|
28
|
-
team_id: team_id,
|
29
|
-
).generate_client_secret
|
30
|
-
|
31
|
-
access_token = SignInWithAppleUserMigrator::AccessTokenGenerator.new(
|
32
|
-
client_id: client_id,
|
33
|
-
client_secret: client_secret,
|
34
|
-
).get_access_token
|
35
|
-
|
36
|
-
transfer_id_generator_client = SignInWithAppleUserMigrator::TransferIdGenerator.new(
|
37
|
-
client_id: client_id,
|
38
|
-
client_secret: client_secret,
|
39
|
-
access_token: access_token,
|
40
|
-
target_team_id: target_team_id,
|
41
|
-
)
|
42
|
-
|
43
25
|
FileUtils.mkdir_p('tmp')
|
44
26
|
result_csv_name = "generated_transfer_ids_#{Time.now.strftime('%Y%m%d%H%M%S')}.csv"
|
45
|
-
|
27
|
+
result_csv_path = File.join('tmp', result_csv_name)
|
46
28
|
File.write("tmp/#{result_csv_name}", "user_id,transfer_id,error\n")
|
47
29
|
|
48
|
-
CSV.open(
|
49
|
-
|
30
|
+
CSV.open(result_csv_path, 'w') do |result_csv|
|
31
|
+
result_csv << %w[user_id transfer_id error]
|
50
32
|
|
51
33
|
CSV.foreach(transfer_user_id_csv_path, headers: true) do |row|
|
52
34
|
user_id = row['user_id']
|
53
35
|
next if user_id.nil? || user_id.empty?
|
54
36
|
|
55
|
-
|
56
|
-
|
37
|
+
client_secret, access_token = token_manager.ensure_valid_token
|
38
|
+
generator = TransferIdGenerator.new(
|
39
|
+
client_id: options[:client_id],
|
40
|
+
client_secret: client_secret,
|
41
|
+
access_token: access_token,
|
42
|
+
target_team_id: target_team_id
|
43
|
+
)
|
44
|
+
|
45
|
+
transfer_id, error = generator.generate_transfer_id(user_id)
|
46
|
+
result_csv << [user_id, transfer_id, error]
|
57
47
|
end
|
58
48
|
end
|
49
|
+
|
59
50
|
end
|
60
51
|
|
61
52
|
desc 'migrate_user_transfer_ids', 'Migrate user transfer IDs'
|
62
|
-
|
63
|
-
option :key_id, required: true, desc: 'Key ID'
|
64
|
-
option :private_key_path, required: true, desc: 'Private Key Path'
|
65
|
-
option :team_id, required: true, desc: 'Team ID'
|
53
|
+
COMMON_OPTIONS.each { |name, opts| option(name, opts) }
|
66
54
|
option :transfer_id_csv_path, required: true, desc: 'Transfer ID CSV Path'
|
67
55
|
|
68
56
|
def migrate_user_transfer_ids
|
69
|
-
|
70
|
-
key_id = options[:key_id]
|
71
|
-
private_key_path = options[:private_key_path]
|
72
|
-
team_id = options[:team_id]
|
57
|
+
token_manager = TokenManager.new(**common_options)
|
73
58
|
transfer_id_csv_path = options[:transfer_id_csv_path]
|
74
59
|
|
75
|
-
client_secret = SignInWithAppleUserMigrator::ClientSecretGenerator.new(
|
76
|
-
client_id: client_id,
|
77
|
-
key_id: key_id,
|
78
|
-
private_key_path: private_key_path,
|
79
|
-
team_id: team_id,
|
80
|
-
).generate_client_secret
|
81
|
-
|
82
|
-
access_token = SignInWithAppleUserMigrator::AccessTokenGenerator.new(
|
83
|
-
client_id: client_id,
|
84
|
-
client_secret: client_secret,
|
85
|
-
).get_access_token
|
86
|
-
|
87
|
-
transfer_id_exchanger_client = SignInWithAppleUserMigrator::TransferIdExchanger.new(
|
88
|
-
client_id: client_id,
|
89
|
-
client_secret: client_secret,
|
90
|
-
access_token: access_token,
|
91
|
-
)
|
92
|
-
|
93
60
|
FileUtils.mkdir_p('tmp')
|
94
61
|
result_csv_name = "exchanged_transfer_ids_#{Time.now.strftime('%Y%m%d%H%M%S')}.csv"
|
95
|
-
|
62
|
+
result_csv_path = File.join('tmp', result_csv_name)
|
96
63
|
File.write("tmp/#{result_csv_name}", "transfer_id,sub,error\n")
|
97
64
|
|
98
|
-
CSV.open(
|
99
|
-
|
65
|
+
CSV.open(result_csv_path, 'w') do |result_csv|
|
66
|
+
result_csv << %w[transfer_id sub email is_private_email error]
|
100
67
|
|
101
68
|
CSV.foreach(transfer_id_csv_path, headers: true) do |row|
|
102
69
|
transfer_id = row['transfer_id']
|
103
70
|
next if transfer_id.nil? || transfer_id.empty?
|
104
71
|
|
105
|
-
|
106
|
-
|
72
|
+
client_secret, access_token = token_manager.ensure_valid_token
|
73
|
+
exchanger = TransferIdExchanger.new(
|
74
|
+
client_id: options[:client_id],
|
75
|
+
client_secret: client_secret,
|
76
|
+
access_token: access_token
|
77
|
+
)
|
78
|
+
|
79
|
+
transfer_id, sub, email, is_private_email, error = exchanger.migrate(transfer_id)
|
80
|
+
result_csv << [transfer_id, sub, email, is_private_email, error]
|
107
81
|
end
|
108
82
|
end
|
109
83
|
end
|
84
|
+
|
85
|
+
private
|
86
|
+
def common_options
|
87
|
+
COMMON_OPTIONS.keys.each_with_object({}) do |key, hash|
|
88
|
+
hash[key] = options[key]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class TokenManager
|
94
|
+
TOKEN_DURATION = 3600
|
95
|
+
TOKEN_REFRESH_THRESHOLD = 300
|
96
|
+
|
97
|
+
def initialize(client_id:, key_id:, private_key_path:, team_id:)
|
98
|
+
@client_id = client_id
|
99
|
+
@key_id = key_id
|
100
|
+
@private_key_path = private_key_path
|
101
|
+
@team_id = team_id
|
102
|
+
@token_generated_at = nil
|
103
|
+
@client_secret = nil
|
104
|
+
@access_token = nil
|
105
|
+
end
|
106
|
+
|
107
|
+
def ensure_valid_token
|
108
|
+
return [@client_secret, @access_token] if valid_token?
|
109
|
+
|
110
|
+
@token_generated_at = Time.now
|
111
|
+
@client_secret = generate_client_secret
|
112
|
+
@access_token = generate_access_token
|
113
|
+
[@client_secret, @access_token]
|
114
|
+
end
|
115
|
+
|
116
|
+
private
|
117
|
+
def valid_token?
|
118
|
+
!@token_generated_at.nil? && (Time.now - @token_generated_at) <= (TOKEN_DURATION - TOKEN_REFRESH_THRESHOLD)
|
119
|
+
end
|
120
|
+
|
121
|
+
def generate_client_secret
|
122
|
+
SignInWithAppleUserMigrator::ClientSecretGenerator.new(
|
123
|
+
client_id: @client_id,
|
124
|
+
key_id: @key_id,
|
125
|
+
private_key_path: @private_key_path,
|
126
|
+
team_id: @team_id
|
127
|
+
).generate_client_secret(iat: @token_generated_at.to_i, exp: @token_generated_at.to_i + TOKEN_DURATION)
|
128
|
+
end
|
129
|
+
|
130
|
+
def generate_access_token
|
131
|
+
SignInWithAppleUserMigrator::AccessTokenGenerator.new(
|
132
|
+
client_id: @client_id,
|
133
|
+
client_secret: @client_secret
|
134
|
+
).get_access_token
|
135
|
+
end
|
110
136
|
end
|
111
137
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sign_in_with_apple_user_migrator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sakurahigashi2
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -102,7 +102,7 @@ licenses:
|
|
102
102
|
- MIT
|
103
103
|
metadata:
|
104
104
|
documentation_uri: https://github.com/sakurahigashi2/sign_in_with_apple_user_migrator
|
105
|
-
post_install_message:
|
105
|
+
post_install_message:
|
106
106
|
rdoc_options: []
|
107
107
|
require_paths:
|
108
108
|
- lib
|
@@ -117,8 +117,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
117
|
- !ruby/object:Gem::Version
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
|
-
rubygems_version: 3.
|
121
|
-
signing_key:
|
120
|
+
rubygems_version: 3.3.25
|
121
|
+
signing_key:
|
122
122
|
specification_version: 4
|
123
123
|
summary: Apple Sign In User Migration Tool
|
124
124
|
test_files: []
|