Skip to content

Commit

Permalink
FBTokenController fetches new access_token if current is invalid
Browse files Browse the repository at this point in the history
- debug_token was failing due to incorrect access token and hidden by
ensure block
- nsarno/knock#11, last comment is correct,
fetch debug token using app_access_token to allow root access to FB API
  • Loading branch information
fkotsian committed Oct 12, 2018
1 parent facd61b commit 0a19d3e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/controllers/facebook_token_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def access_token
end

def oauth
@oauth = Koala::Facebook::OAuth.new(auth_params[:client_id], Koala.config.app_secret, auth_params[:redirect_uri])
@oauth ||= Koala::Facebook::OAuth.new(auth_params[:client_id], Koala.config.app_secret, auth_params[:redirect_uri])
end

def auth_params
Expand Down
16 changes: 9 additions & 7 deletions lib/services/facebook_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ class FacebookService

def self.valid_token?(access_token)
status = false
begin
# We need to check if the access_token is valid for our FB APP. Source: https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow#checktoken
debug_token = Koala::Facebook::API.new(access_token).debug_token(app_access_token_info['access_token'])
status = true if debug_token['data']['is_valid']
ensure
return status
end

# We need to check if the access_token is valid for our FB APP. Source: https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow#checktoken
# - use app access token to new up API, so can test user access_token
debug_token = Koala::Facebook::API
.new(app_access_token_info['access_token'])
.debug_token(access_token)
status = true if debug_token['data']['is_valid']

status
end

def self.fetch_data(access_token)
Expand Down

0 comments on commit 0a19d3e

Please sign in to comment.