lib/omniauth/strategies/oauth2.rb in oa-oauth-0.2.0.beta5 vs lib/omniauth/strategies/oauth2.rb in oa-oauth-0.2.0

- old
+ new

@@ -55,18 +55,17 @@ protected def request_phase redirect client.web_server.authorize_url({:redirect_uri => callback_url}.merge(options)) end - + def callback_phase if request.params['error'] || request.params['error_reason'] raise CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri']) end - verifier = request.params['code'] - @access_token = client.web_server.get_access_token(verifier, {:redirect_uri => callback_url}.merge(options)) + @access_token = build_access_token if @access_token.expires? && @access_token.expires_in <= 0 client.request(:post, client.access_token_url, { 'client_id' => client_id, 'grant_type' => 'refresh_token', @@ -79,9 +78,14 @@ super rescue ::OAuth2::HTTPError, ::OAuth2::AccessDenied, CallbackError => e fail!(:invalid_credentials, e) rescue ::MultiJson::DecodeError => e fail!(:invalid_response, e) + end + + def build_access_token + verifier = request.params['code'] + client.web_server.get_access_token(verifier, {:redirect_uri => callback_url}.merge(options)) end def auth_hash OmniAuth::Utils.deep_merge(super, { 'credentials' => {