standard_id 0.2.2 → 0.2.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: ff3da0872b1957015180ea523a6ece07c7e5182415627edefd1b7cb204123555
4
- data.tar.gz: 1b18e14597e237f2a6082df2210174f97b05f4febd02a729cad2509ffaf9dd60
3
+ metadata.gz: b187dd81d274ace6321becb8a2be32bf28968ab27d845d698294ff2ec448ad53
4
+ data.tar.gz: 3deb68b18b7d5ad8a4075c303ebe03cf93fc0fd0a74b1ef399736688e62f35ab
5
5
  SHA512:
6
- metadata.gz: 258469a8242bd871aef309f677077daca3c5e36cb6c62c748d698dc420b5997738adefe404da90928e2e98514d775f2fc1caf7f71ee1f40d3fa1228ac5346dc8
7
- data.tar.gz: 41e96e5bf1aec93e33f36f3a97b81ba26609d2c854e3cc4887186c6cd4717dd8fb2fe73eaf0ac57c03a0097fc47381494bec33497cff8880e3a55ba822fc75ac
6
+ metadata.gz: 1e64c713cd3861aba0ceb1f946d881effc025439807eb30e7ea373052c9890e077a654257e940e6379c7ae743a90fa8736ece2139bb92dd2b9a284b943c48ed2
7
+ data.tar.gz: c61fd9e8033cbbd91903e31933b3d1f0c77b34298a672e77b77af0478b3a64eec011674a1c21b3db5111f60277baf3a71357cd021c45eb2e1dba7222fe828e62
@@ -16,7 +16,8 @@ module StandardId
16
16
  params,
17
17
  request,
18
18
  account:,
19
- connection: provider.provider_name
19
+ connection: provider.provider_name,
20
+ scopes: params[:scope] || params[:scopes]
20
21
  )
21
22
 
22
23
  token_response = flow.execute
@@ -24,7 +25,7 @@ module StandardId
24
25
  provider: provider.provider_name,
25
26
  social_info:,
26
27
  provider_tokens:,
27
- account:
28
+ account:,
28
29
  )
29
30
  render json: token_response, status: :ok
30
31
  end
@@ -60,6 +60,7 @@ StandardId.configure do |c|
60
60
  # c.social.apple_key_id = ENV["APPLE_KEY_ID"]
61
61
  # c.social.apple_team_id = ENV["APPLE_TEAM_ID"]
62
62
  # c.social.allowed_redirect_url_prefixes = ["sidekicklabs://"]
63
+ # c.social.available_scopes = ["profile", "email", "offline_access"]
63
64
  # c.social.social_account_attributes = ->(social_info:, provider:) {
64
65
  # {
65
66
  # email: social_info[:email],
@@ -55,5 +55,6 @@ StandardConfig.schema.draw do
55
55
  scope :social do
56
56
  field :social_account_attributes, type: :any, default: nil
57
57
  field :allowed_redirect_url_prefixes, type: :array, default: []
58
+ field :available_scopes, type: :array, default: -> { [] }
58
59
  end
59
60
  end
@@ -1,12 +1,13 @@
1
1
  module StandardId
2
2
  module Oauth
3
3
  class SocialFlow < TokenGrantFlow
4
- attr_reader :account, :connection, :original_params
4
+ attr_reader :account, :connection, :scopes
5
5
 
6
- def initialize(params, request, account:, connection:)
6
+ def initialize(params, request, account:, connection:, scopes:)
7
7
  super(params, request)
8
8
  @account = account
9
9
  @connection = connection
10
+ @scopes = validate_and_normalize_scopes(scopes)
10
11
  end
11
12
 
12
13
  def authenticate!
@@ -24,7 +25,7 @@ module StandardId
24
25
  end
25
26
 
26
27
  def token_scope
27
- nil
28
+ scopes
28
29
  end
29
30
 
30
31
  def grant_type
@@ -51,6 +52,22 @@ module StandardId
51
52
  base_payload = super(expires_in)
52
53
  base_payload.merge(provider: @connection).compact
53
54
  end
55
+
56
+ def validate_and_normalize_scopes(scopes)
57
+ return nil if scopes.blank?
58
+
59
+ available_scopes = StandardId.config.social.available_scopes
60
+ return scopes if available_scopes.blank?
61
+
62
+ requested_scopes = scopes.to_s.split(/\s+/).reject(&:blank?).uniq
63
+ invalid_scopes = requested_scopes - available_scopes.map(&:to_s)
64
+
65
+ if invalid_scopes.any?
66
+ raise StandardId::InvalidScopeError, "Invalid scope(s): #{invalid_scopes.join(', ')}. Available scopes: #{available_scopes.join(', ')}"
67
+ end
68
+
69
+ requested_scopes.join(" ")
70
+ end
54
71
  end
55
72
  end
56
73
  end
@@ -1,3 +1,3 @@
1
1
  module StandardId
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standard_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaryl Sim