Codebase list ruby-omniauth-facebook / 6ae20dc
consistent max. line length to 120. use tomdoc comment style Mark Dodwell 10 years ago
1 changed file(s) with 12 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
7676
7777 def request_phase
7878 if signed_request_contains_access_token?
79 # if we already have an access token, we can just hit the
80 # callback URL directly and pass the signed request along
79 # If we already have an access token, we can just hit the callback URL directly and pass the signed request.
8180 params = { :signed_request => raw_signed_request }
8281 query = Rack::Utils.build_query(params)
8382
9291 end
9392 end
9493
95 # NOTE if we're using code from the signed request
96 # then FB sets the redirect_uri to '' during the authorize
97 # phase + it must match during the access_token phase:
98 # https://github.com/facebook/php-sdk/blob/master/src/base_facebook.php#L348
94 # NOTE If we're using code from the signed request then FB sets the redirect_uri to '' during the authorize
95 # phase and it must match during the access_token phase:
96 # https://github.com/facebook/php-sdk/blob/master/src/base_facebook.php#L348
9997 def callback_url
10098 if @authorization_code_from_signed_request
10199 ''
108106 options.access_token_options.inject({}) { |h,(k,v)| h[k.to_sym] = v; h }
109107 end
110108
111 ##
112 # You can pass +display+, +scope+, or +auth_type+ params to the auth request, if
113 # you need to set them dynamically. You can also set these options
114 # in the OmniAuth config :authorize_params option.
109 # You can pass +display+, +scope+, or +auth_type+ params to the auth request, if you need to set them dynamically.
110 # You can also set these options in the OmniAuth config :authorize_params option.
115111 #
116112 # /auth/facebook?display=popup
117 #
118113 def authorize_params
119114 super.tap do |params|
120115 %w[display scope auth_type].each do |v|
127122 end
128123 end
129124
130 ##
131125 # Parse signed request in order, from:
132126 #
133 # 1. the request 'signed_request' param (server-side flow from canvas pages) or
134 # 2. a cookie (client-side flow via JS SDK)
135 #
127 # 1. The request 'signed_request' param (server-side flow from canvas pages) or
128 # 2. A cookie (client-side flow via JS SDK)
136129 def signed_request
137130 @signed_request ||= raw_signed_request &&
138131 parse_signed_request(raw_signed_request)
162155 request.cookies["fbsr_#{client.id}"]
163156 end
164157
165 ##
166 # If the signed_request comes from a FB canvas page and the user
167 # has already authorized your application, the JSON object will be
168 # contain the access token.
158 # If the signed_request comes from a FB canvas page and the user has already authorized your application, the JSON
159 # object will be contain the access token.
169160 #
170161 # https://developers.facebook.com/docs/authentication/canvas/
171 #
172162 def signed_request_contains_access_token?
173163 signed_request &&
174164 signed_request['oauth_token']
175165 end
176166
177 ##
178167 # Picks the authorization code in order, from:
179168 #
180 # 1. the request 'code' param (manual callback from standard server-side flow)
181 # 2. a signed request (see #signed_request for more)
182 #
169 # 1. The request 'code' param (manual callback from standard server-side flow)
170 # 2. A signed request (see #signed_request for more)
183171 def with_authorization_code!
184172 if request.params.key?('code')
185173 yield