Class: Checkdin::UserBridge
- Inherits:
-
Object
- Object
- Checkdin::UserBridge
- Defined in:
- lib/checkdin/user_bridge.rb
Constant Summary collapse
- CHECKDIN_DEFAULT_LANDING =
'https://app.checkd.in/user_landing?'
Instance Attribute Summary collapse
-
#checkdin_landing_url ⇒ Object
readonly
Returns the value of attribute checkdin_landing_url.
-
#client_identifier ⇒ Object
readonly
Returns the value of attribute client_identifier.
Instance Method Summary collapse
-
#build_authenticated_parameters(email, user_identifier, authentication_action = nil) ⇒ Object
Private: Build a signed hash of parameters for redirecting the user to checkd.in.
-
#initialize(options) ⇒ UserBridge
constructor
Used to build the authenticated parameters for logging in an end-user on checkd.in via a redirect.
-
#login_url(options) ⇒ Object
Public: Build a full signed url for logging a specific user into checkd.in.
Constructor Details
#initialize(options) ⇒ UserBridge
Used to build the authenticated parameters for logging in an end-user on checkd.in via a redirect.
options - a hash with a the following values defined:
:client_identifier - REQUIRED, the same client identifier used when accessing the regular
API methods.
:bridge_secret - REQUIRED, previously agreed upon shared secret for the user bridge.
This is NOT the shared secret used for accessing the backend API,
please do not confuse the two.
:checkdin_landing_url - OPTIONAL, the value will default to CHECKDIN_DEFAULT_LANDING
if not given. Please set this value as directed by Checkd In.
Examples
bridge = Checkdin::UserBridge.new(:client_identifier => 'YOUR_ASSIGNED_CLIENT_IDENTIFIER',
:bridge_secret => 'YOUR_ASSIGNED_BRIDGE_SECRET')
redirect_to bridge.login_url(:email => '[email protected]',
:user_identifier => '112-fixed-user-identifier')
27 28 29 30 31 32 33 34 |
# File 'lib/checkdin/user_bridge.rb', line 27 def initialize @client_identifier = .delete(:client_identifier) or raise ArgumentError.new("No :client_identifier given") @bridge_secret = .delete(:bridge_secret) or raise ArgumentError.new("No :bridge_secret given") @checkdin_landing_url = .delete(:checkdin_landing_url) || CHECKDIN_DEFAULT_LANDING raise ArgumentError.new("Unknown arguments given: #{.keys.inspect}") unless .empty? end |
Instance Attribute Details
#checkdin_landing_url ⇒ Object (readonly)
Returns the value of attribute checkdin_landing_url.
6 7 8 |
# File 'lib/checkdin/user_bridge.rb', line 6 def checkdin_landing_url @checkdin_landing_url end |
#client_identifier ⇒ Object (readonly)
Returns the value of attribute client_identifier.
5 6 7 |
# File 'lib/checkdin/user_bridge.rb', line 5 def client_identifier @client_identifier end |
Instance Method Details
#build_authenticated_parameters(email, user_identifier, authentication_action = nil) ⇒ Object
Private: Build a signed hash of parameters for redirecting the user to checkd.in.
Returns a hash including a secure message digest and the current timestamp
61 62 63 64 65 |
# File 'lib/checkdin/user_bridge.rb', line 61 def build_authenticated_parameters email, user_identifier, authentication_action = nil build_request(email, user_identifier, authentication_action).tap do |request| request['digest'] = digest_request(request) end end |
#login_url(options) ⇒ Object
Public: Build a full signed url for logging a specific user into checkd.in. Notice: you MUST NOT reuse the result of this method, as it expires automatically based on time.
options - a hash with the following values defined:
email - REQUIRED, email address of the user, MAY have different values for a given
user over time.
user_identifier - REQUIRED, your unique identifier for the user, MUST NOT change over time.
authentication_action - OPTIONAL, the given action will be performed immediately,
and the user redirected back to your site afterwards.
Returns a URL you can use for redirecting a user. Notice this will expire, so it should be generated and used only when a user actually wants to log into checkd.in.
48 49 50 51 52 53 54 55 56 |
# File 'lib/checkdin/user_bridge.rb', line 48 def login_url email = .delete(:email) or raise ArgumentError.new("No :email passed for user") user_identifier = .delete(:user_identifier) or raise ArgumentError.new("No :user_identifier passed for user") authentication_action = .delete(:authentication_action) authenticated_parameters = build_authenticated_parameters(email, user_identifier, authentication_action) [checkdin_landing_url, authenticated_parameters.to_query].join end |