Class: TentD::API::Apps::CreateAuthorization

Inherits:
Middleware
  • Object
show all
Defined in:
lib/tentd/api/apps.rb

Instance Method Summary collapse

Methods inherited from Middleware

#call, #initialize

Methods included from TentD::API::Authorizable

#authorize_env!, #authorize_env?

Constructor Details

This class inherits a constructor from TentD::API::Middleware

Instance Method Details

#action(env) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/tentd/api/apps.rb', line 78

def action(env)
  unless authorize_env?(env, :write_apps)
    if env.params.data.code
      return AuthorizationTokenExchange.new(@app).call(env)
    else
      authorize_env!(env, :write_apps)
    end
  end

  if app = Model::App.first(:id => env.params.app_id)
    env.authorized_scopes << :authorization_token
    authorization = app.authorizations.create_from_params(
      :app_id => env.params.app_id,
      :notification_url => env.params.data.notification_url,
      :post_types => env.params.data.post_types.to_a.map { |url| URI.decode(url) },
      :profile_info_types => env.params.data.profile_info_types.to_a.map { |url| URI.decode(url) },
      :scopes => env.params.data.scopes
    )
    env.response = authorization
  end
  env
end