Class: Spree::OauthApplication
- Inherits:
-
Object
- Object
- Spree::OauthApplication
- Includes:
- Doorkeeper::Orm::ActiveRecord::Mixins::Application
- Defined in:
- app/models/spree/oauth_application.rb
Overview
A registered OAuth client: an MCP client today, a marketplace app or a merchant-approved integration later. Clients are pre-registered rather than dynamically registered — RFC 7591 is deprecated, and the consumer clients worth supporting need no registration endpoint.
Instance Method Summary collapse
- #authorized_at ⇒ ActiveSupport::TimeWithZone?
-
#authorized_by ⇒ Object?
Who approved this application's access, and when.
-
#connected? ⇒ Boolean
Whether anything can still reach the store with this registration.
-
#last_authorized_at ⇒ ActiveSupport::TimeWithZone?
When this application last obtained a token that still works.
-
#live_token_scopes ⇒ Array<String>
What this application may currently do, as permission keys.
Instance Method Details
#authorized_at ⇒ ActiveSupport::TimeWithZone?
87 88 89 |
# File 'app/models/spree/oauth_application.rb', line 87 def oldest_live_token&.created_at end |
#authorized_by ⇒ Object?
Who approved this application's access, and when.
Read from the oldest live token, because that is the consent still in force — a later token refreshes an existing grant rather than replacing who gave it. On the screen that decides whether to revoke, "Claude can read your orders" is only half the story without the person who allowed it.
82 83 84 |
# File 'app/models/spree/oauth_application.rb', line 82 def oldest_live_token&.resource_owner end |
#connected? ⇒ Boolean
Whether anything can still reach the store with this registration.
The screen lists every registered client, so a row with no live token may be one nobody has connected yet or one whose access was revoked — and an empty permission list reads the same either way. A merchant pressing Revoke has to see that it worked.
46 47 48 |
# File 'app/models/spree/oauth_application.rb', line 46 def connected? live_access_tokens.any? end |
#last_authorized_at ⇒ ActiveSupport::TimeWithZone?
When this application last obtained a token that still works.
Not the last call it made: a token is minted once and then used for hours, and nothing records a call. Reporting this as "last used" would let a merchant read an actively running agent as idle, which is the opposite of what the connected-apps screen is for.
69 70 71 |
# File 'app/models/spree/oauth_application.rb', line 69 def live_access_tokens.map(&:created_at).max end |
#live_token_scopes ⇒ Array<String>
What this application may currently do, as permission keys.
Read from the tokens rather than the registration: a client is
registered once and granted per consent, so the registration's own
scopes column stays empty.
57 58 59 |
# File 'app/models/spree/oauth_application.rb', line 57 def live_token_scopes live_access_tokens.flat_map { |token| token.scopes.to_a }.uniq.sort end |