class Stormpath::Resource::Application

Public Class Methods

load(composite_url) click to toggle source
   # File lib/stormpath-sdk/resource/application.rb
48 def self.load(composite_url)
49   builder = Stormpath::Util::UriBuilder.new(composite_url)
50   api_key_id, api_key_secret = builder.userinfo.split(':')
51 
52   client = Stormpath::Client.new(
53     api_key: {
54       id: api_key_id,
55       secret: api_key_secret
56     }
57   )
58 
59   application_path = builder.uri.path.slice(/\/applications(.)*$/)
60   client.applications.get(application_path)
61 rescue
62   raise LoadError
63 end

Public Instance Methods

authenticate_account(request) click to toggle source
    # File lib/stormpath-sdk/resource/application.rb
106 def authenticate_account(request)
107   Stormpath::Authentication::BasicAuthenticator.new(data_store).authenticate(href, request)
108 end
authenticate_oauth(request) click to toggle source
    # File lib/stormpath-sdk/resource/application.rb
114 def authenticate_oauth(request)
115   Stormpath::Oauth::Authenticator.new(data_store).authenticate(href, request)
116 end
create_id_site_url(options = {}) click to toggle source
   # File lib/stormpath-sdk/resource/application.rb
65 def create_id_site_url(options = {})
66   raise Stormpath::Oauth::Error, :jwt_cb_uri_incorrect if options[:callback_uri].blank?
67 
68   base = client.data_store.base_url.sub("v#{Stormpath::DataStore::DEFAULT_API_VERSION}", 'sso')
69   base += '/logout' if options[:logout]
70 
71   token = JWT.encode(jwt_token_payload(options), client.data_store.api_key.secret, 'HS256')
72   "#{base}?jwtRequest=#{token}"
73 end
get_provider_account(request) click to toggle source
    # File lib/stormpath-sdk/resource/application.rb
110 def get_provider_account(request)
111   Stormpath::Provider::AccountResolver.new(data_store, href, request).resolve_provider_account
112 end
handle_id_site_callback(response_url) click to toggle source
   # File lib/stormpath-sdk/resource/application.rb
75 def handle_id_site_callback(response_url)
76   assert_not_nil(response_url, 'No response provided. Please provide response object.')
77 
78   uri = URI(response_url)
79   params = CGI.parse(uri.query)
80   token = params['jwtResponse'].first
81 
82   begin
83     jwt_response, _header = JWT.decode(token, client.data_store.api_key.secret)
84   rescue JWT::ExpiredSignature => error
85     # JWT raises error if the signature expired, we need to capture this and
86     # reraise IdSite::Error
87     raise Stormpath::Oauth::Error, :jwt_expired
88   end
89 
90   id_site_result = Stormpath::IdSite::IdSiteResult.new(jwt_response)
91 
92   raise Stormpath::Oauth::Error, :jwt_invalid if id_site_result.jwt_invalid?(api_key_id)
93 
94   id_site_result
95 end
register_service_provider(options = {}) click to toggle source
    # File lib/stormpath-sdk/resource/application.rb
118 def register_service_provider(options = {})
119   Stormpath::Authentication::RegisterServiceProvider.new(
120     saml_policy.identity_provider, options
121   ).call
122 end
send_password_reset_email(email, account_store: nil) click to toggle source
    # File lib/stormpath-sdk/resource/application.rb
 97 def send_password_reset_email(email, account_store: nil)
 98   password_reset_token = create_password_reset_token(email, account_store: account_store)
 99   password_reset_token.account
100 end
verify_password_reset_token(token) click to toggle source
    # File lib/stormpath-sdk/resource/application.rb
102 def verify_password_reset_token(token)
103   password_reset_tokens.get(token).account
104 end

Private Instance Methods

account_store_to_hash(account_store) click to toggle source
    # File lib/stormpath-sdk/resource/application.rb
152 def account_store_to_hash(account_store)
153   case account_store
154   when Stormpath::Resource::Organization
155     { name_key: account_store.name_key }
156   when Stormpath::Resource::Group, Stormpath::Resource::Directory
157     { href: account_store.href }
158   when Hash
159     account_store
160   else
161     raise ArgumentError, 'Account store has to be passed either as an resource or a hash'
162   end
163 end
api_key_id() click to toggle source
    # File lib/stormpath-sdk/resource/application.rb
142 def api_key_id
143   client.data_store.api_key.id
144 end
create_password_reset_token(email, account_store: nil) click to toggle source
    # File lib/stormpath-sdk/resource/application.rb
146 def create_password_reset_token(email, account_store: nil)
147   params = { email: email }
148   params[:account_store] = account_store_to_hash(account_store) if account_store
149   password_reset_tokens.create(params)
150 end
jwt_token_payload(options) click to toggle source
    # File lib/stormpath-sdk/resource/application.rb
126 def jwt_token_payload(options)
127   {}.tap do |payload|
128     payload[:jti] = UUID.method(:random_create).call.to_s
129     payload[:iat] = Time.now.to_i
130     payload[:iss] = client.data_store.api_key.id
131     payload[:sub] = href
132     payload[:state] = options[:state] || ''
133     payload[:path] = options[:path] || ''
134     payload[:cb_uri] = options[:callback_uri]
135     payload[:sof] = options[:show_organization_field]
136     payload[:onk] = options[:organization_name_key]
137     payload[:usd] = options[:use_subdomain]
138     payload[:require_mfa] = options[:require_mfa]
139   end.compact
140 end