Method: Ishapi::ApplicationController#long_term_token
- Defined in:
- app/controllers/ishapi/application_controller.rb
#long_term_token ⇒ Object
POST /api/users/long_term_token , a FB login flow
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/ishapi/application_controller.rb', line 9 def long_term_token accessToken = request.headers[:accessToken] accessToken ||= params[:accessToken] params['domain'] = 'tgm.piousbox.com' response = ::HTTParty.get "https://graph.facebook.com/v5.0/oauth/access_token?grant_type=fb_exchange_token&" + "client_id=#{::FB[params['domain']][:app]}&client_secret=#{::FB[params['domain']][:secret]}&" + "fb_exchange_token=#{accessToken}" j = JSON.parse response.body @long_term_token = j['access_token'] @graph = Koala::Facebook::API.new( accessToken ) @me = @graph.get_object( 'me', :fields => 'email' ) @current_user = User.where( :email => @me['email'] ).first @current_profile = Ish::UserProfile.find_by( email: @current_user.email ) # send the jwt to client @jwt_token = encode(user_id: @current_user.id.to_s) render json: { email: @current_user.email, jwt_token: @jwt_token, long_term_token: @long_term_token, n_unlocks: @current_profile.n_unlocks, } end |