Method: ZendeskConfiguration#zendesk_url
- Defined in:
- lib/app/models/concerns/zendesk_configuration.rb
#zendesk_url(forward_to: zendesk_documentation_path, user: nil) ⇒ Object
Generate a Zendesk URL
If a user is passed in and Zendesk is configured then return a JWT enabled URL for SSO authentication to Zendesk.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/app/models/concerns/zendesk_configuration.rb', line 67 def zendesk_url(forward_to: zendesk_documentation_path, user: nil) path = if zendesk_configured? && user.present? time_now = Time.now.to_i jti = "#{time_now}/#{rand(36**64).to_s(36)}" payload = { jwt: JWT.encode({ iat: time_now, # Seconds since epoch, determine when this token is stale jti: jti, # Unique token identifier, helps prevent replay attacks name: user.name, email: user.email }, zendesk_token), return_to: CGI.escape([zendesk_base_url, forward_to].join('/')) } ['access/jwt', payload.to_query].join('?') else forward_to end [zendesk_base_url, path].join('/') end |