fastlane-plugin-firebase_app_distribution 0.3.3 → 0.3.4.pre.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a1fbbe97c9bb43345aa73b821b9a0f192bbd0f6820917923927377880f58b03
4
- data.tar.gz: 40cf095bae9f86eb68015545991ccdcae9b2024851cb2e991d12c6f145cf68f8
3
+ metadata.gz: 91839fcf765eec633a450478d6ea098749fbe5aface36f1ee02b0b054a4df3cf
4
+ data.tar.gz: 5548c844a4c5bfb9bd99b8895d0a2d83f2a2af0c77e030df97629183684096a2
5
5
  SHA512:
6
- metadata.gz: 6b1c43fd6f71064334580d10842a1e1b31904e769140124ea5bbca7f6111771c5611fc9e74e08e6b5039ee38e8a0996f020a0ae2abdccd2f0f9438273b2514b4
7
- data.tar.gz: 32491201cbcc854397f498b7c7064d296fe4220396afdf46d3c9a600e58af1f0af8ba9a2b74a4127cc6d87639fb6e9320cf4173076f9bf9a03b9a675c83bdaa8
6
+ metadata.gz: 86be9d6224a6fbc54124a5f9de5d35932086eca74541b43a7adf4c23d4b4d2ffc88a0c7b8e17f6cd6aa8a4755225856e3164f622d0df52f357795e91ad7a8e57
7
+ data.tar.gz: ef77e82347bee131ab33ec38cb9c14b95db3c0b3e09969af2cf3e5c9544c4ecb5fbdb64e7d9792098f3060ba7ad18c918b27ad412b8910e109353d2a88bbc59e
@@ -1,11 +1,9 @@
1
1
  require 'googleauth'
2
- require 'googleauth/stores/file_token_store'
3
2
  require "fileutils"
4
3
 
5
4
  module Fastlane
6
5
  module Actions
7
6
  class FirebaseAppDistributionLoginAction < Action
8
- OOB_URI = "urn:ietf:wg:oauth:2.0:oob"
9
7
  SCOPE = "https://www.googleapis.com/auth/cloud-platform"
10
8
 
11
9
  # In this type of application, the client secret is not treated as a secret.
@@ -14,24 +12,65 @@ module Fastlane
14
12
  CLIENT_SECRET = "j9iVZfS8kkCEFUPaAeJV0sAi"
15
13
 
16
14
  def self.run(params)
15
+ callback_uri = "http://localhost:#{params[:port]}"
17
16
  client_id = Google::Auth::ClientId.new(CLIENT_ID, CLIENT_SECRET)
18
- authorizer = Google::Auth::UserAuthorizer.new(client_id, SCOPE, nil)
19
- url = authorizer.get_authorization_url(base_url: OOB_URI)
17
+ authorizer = Google::Auth::UserAuthorizer.new(client_id, SCOPE, nil, callback_uri)
18
+
19
+ # Create an anti-forgery state token as described here:
20
+ # https://developers.google.com/identity/protocols/OpenIDConnect#createxsrftoken
21
+ state = SecureRandom.hex(16)
22
+ url = authorizer.get_authorization_url(state: state)
20
23
 
21
24
  UI.message("Open the following address in your browser and sign in with your Google account:")
22
25
  UI.message(url)
23
- UI.message("")
24
- code = UI.input("Enter the resulting code here: ")
25
- credentials = authorizer.get_credentials_from_code(code: code, base_url: OOB_URI)
26
- UI.message("")
27
26
 
27
+ response_params = get_authorization_code(params[:port])
28
+
29
+ # Confirm that the state in the response matches the state token used to
30
+ # generate the authorization URL.
31
+ unless state == response_params['state'][0]
32
+ UI.crash!('An error has occurred. The state parameter in the authorization response does not match the expected state, which could mean that a malicious attacker is trying to make a login request.')
33
+ end
34
+
35
+ user_credentials = authorizer.get_credentials_from_code(
36
+ code: response_params['code'][0]
37
+ )
28
38
  UI.success("Set the refresh token as the FIREBASE_TOKEN environment variable")
29
- UI.success("Refresh Token: #{credentials.refresh_token}")
30
- rescue Signet::AuthorizationError
31
- UI.error("The code you entered is invalid. Copy and paste the code and try again.")
39
+ UI.success("Refresh Token: #{user_credentials.refresh_token}")
32
40
  rescue => error
33
41
  UI.error(error.to_s)
34
- UI.crash!("An error has occured, please login again.")
42
+ UI.crash!("An error has occurred, please login again.")
43
+ end
44
+
45
+ def self.get_authorization_code(port)
46
+ begin
47
+ server = TCPServer.open(port)
48
+ rescue Errno::EADDRINUSE => error
49
+ UI.error(error.to_s)
50
+ UI.crash!("Port #{port} is in use. Please specify a different one using the port parameter.")
51
+ end
52
+ client = server.accept
53
+ callback_request = client.readline
54
+ # Use a regular expression to extract the request line from the first line of
55
+ # the callback request, e.g.:
56
+ # GET /?code=AUTH_CODE&state=XYZ&scope=... HTTP/1.1
57
+ matcher = /GET +([^ ]+)/.match(callback_request)
58
+ response_params = CGI.parse(URI.parse(matcher[1]).query) unless matcher.nil?
59
+
60
+ client.puts("HTTP/1.1 200 OK")
61
+ client.puts("Content-Type: text/html")
62
+ client.puts("")
63
+ client.puts("<b>")
64
+ if response_params['code'].nil?
65
+ client.puts("Failed to retrieve authorization code.")
66
+ else
67
+ client.puts("Authorization code was successfully retrieved.")
68
+ end
69
+ client.puts("</b>")
70
+ client.puts("<p>Please check the console output.</p>")
71
+ client.close
72
+
73
+ return response_params
35
74
  end
36
75
 
37
76
  #####################################################
@@ -55,6 +94,18 @@ module Fastlane
55
94
  def self.is_supported?(platform)
56
95
  [:ios, :android].include?(platform)
57
96
  end
97
+
98
+ def self.available_options
99
+ [
100
+ FastlaneCore::ConfigItem.new(key: :port,
101
+ env_name: "FIREBASEAPPDISTRO_LOGIN_PORT",
102
+ description: "Port for the local web server which receives the response from Google's authorization server",
103
+ default_value: "8081",
104
+ optional: true,
105
+ type: String)
106
+
107
+ ]
108
+ end
58
109
  end
59
110
  end
60
111
  end
@@ -24,13 +24,12 @@ module Fastlane
24
24
  value
25
25
  end
26
26
 
27
- # Returns the array representation of a string with comma seperated values.
28
- #
29
- # Does not work with strings whose individual values have spaces. EX "Hello World" the space will be removed to "HelloWorld"
27
+ # Returns the array representation of a string with trimmed comma
28
+ # seperated values.
30
29
  def string_to_array(string)
31
30
  return nil if string.nil? || string.empty?
32
- string_array = string.gsub(/\s+/, '').split(",")
33
- return string_array
31
+ # Strip string and then strip individual values
32
+ string.strip.split(",").map(&:strip)
34
33
  end
35
34
 
36
35
  def parse_plist(path)
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module FirebaseAppDistribution
3
- VERSION = "0.3.3"
3
+ VERSION = "0.3.4.pre.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-firebase_app_distribution
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Natchev
8
8
  - Manny Jimenez
9
9
  - Alonso Salas Infante
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-03-22 00:00:00.000000000 Z
13
+ date: 2022-04-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: pry
@@ -138,7 +138,7 @@ dependencies:
138
138
  - - ">="
139
139
  - !ruby/object:Gem::Version
140
140
  version: 2.127.1
141
- description:
141
+ description:
142
142
  email:
143
143
  - snatchev@google.com
144
144
  - mannyjimenez@google.com
@@ -168,7 +168,7 @@ homepage: https://github.com/fastlane/fastlane-plugin-firebase_app_distribution
168
168
  licenses:
169
169
  - MIT
170
170
  metadata: {}
171
- post_install_message:
171
+ post_install_message:
172
172
  rdoc_options: []
173
173
  require_paths:
174
174
  - lib
@@ -179,12 +179,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
179
179
  version: '0'
180
180
  required_rubygems_version: !ruby/object:Gem::Requirement
181
181
  requirements:
182
- - - ">="
182
+ - - ">"
183
183
  - !ruby/object:Gem::Version
184
- version: '0'
184
+ version: 1.3.1
185
185
  requirements: []
186
- rubygems_version: 3.2.32
187
- signing_key:
186
+ rubygems_version: 3.1.4
187
+ signing_key:
188
188
  specification_version: 4
189
189
  summary: Release your beta builds to Firebase App Distribution. https://firebase.google.com/docs/app-distribution
190
190
  test_files: []