{"record":{"id":"03b9e8397c591b04","repo":"arsduo/koala","slug":"build-url-must-get-a-callback-either-from-the-oaut","errorCode":null,"errorMessage":"build_url must get a callback either from the OAuth object or in the parameters!","messagePattern":"build_url must get a callback either from the OAuth object or in the parameters!","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/koala/oauth.rb","lineNumber":335,"sourceCode":"      # base 64\n      # directly from https://github.com/facebook/crypto-request-examples/raw/master/sample.rb\n      def base64_url_decode(str)\n        str += '=' * (4 - str.length.modulo(4))\n        Base64.decode64(str.tr('-_', '+/'))\n      end\n\n      def server_url(type)\n        url = \"https://#{Koala.config.send(type)}\"\n        if version = Koala.config.api_version\n          \"#{url}/#{version}\"\n        else\n          url\n        end\n      end\n\n      def build_url(type, path, require_redirect_uri = false, url_options = {})\n        if require_redirect_uri && !(url_options[:redirect_uri] ||= url_options.delete(:callback) || @oauth_callback_url)\n          raise ArgumentError, \"build_url must get a callback either from the OAuth object or in the parameters!\"\n        end\n        params = Koala::HTTPService.encode_params(url_options)\n        \"#{server_url(type)}#{path}?#{params}\"\n      end\n    end\n  end\nend\n","sourceCodeStart":317,"sourceCodeEnd":343,"githubUrl":"https://github.com/arsduo/koala/blob/47d052063ef8b5644fb59e279da0b52687999f55/lib/koala/oauth.rb#L317-L343","documentation":"url_for_oauth_code, url_for_access_token, and url_for_dialog all delegate to build_url with require_redirect_uri = true. The redirect URI must come from url_options[:redirect_uri] (the legacy alias :callback is also accepted) or from @oauth_callback_url, the third argument of Koala::Facebook::OAuth.new; if none is present, build_url raises ArgumentError because a Facebook dialog or token URL without a callback cannot complete the flow.","triggerScenarios":"Building OAuth.new(app_id, app_secret) without the third argument and then calling url_for_oauth_code, url_for_access_token(code), or url_for_dialog(:feed) without :redirect_uri in the options; or Koala.config.oauth_callback_url being nil in an environment where the constructor argument is also omitted.","commonSituations":"Multi-environment apps where only production sets the callback; refactors that drop the third constructor argument; passing the unsupported key :callback_url (accepted keys are :redirect_uri and :callback) and silently still getting nil.","solutions":["Pass the callback as the third constructor argument: Koala::Facebook::OAuth.new(app_id, app_secret, \"https://example.com/auth/facebook/callback\").","Or set it once globally with Koala.configure { |config| config.oauth_callback_url = ENV[\"FB_CALLBACK_URL\"] }.","Or pass :redirect_uri per call for flows that intentionally use a different callback.","Use the exact option keys :redirect_uri or :callback; anything else is ignored and reproduces the error."],"exampleFix":"// before\n@oauth = Koala::Facebook::OAuth.new(APP_ID, APP_SECRET)\nurl = @oauth.url_for_oauth_code\n\n// after\n@oauth = Koala::Facebook::OAuth.new(APP_ID, APP_SECRET, \"https://example.com/auth/facebook/callback\")\nurl = @oauth.url_for_oauth_code","handlingStrategy":"validation","validationCode":"cb = ENV[\"FB_CALLBACK_URL\"]\nraise ArgumentError, \"FB_CALLBACK_URL not configured\" if cb.to_s.empty?\n@oauth = Koala::Facebook::OAuth.new(ENV.fetch(\"FB_APP_ID\"), ENV.fetch(\"FB_APP_SECRET\"), cb)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Configure the callback URL once in an initializer from ENV and pass it to every OAuth instance","Add a boot-time config check that fails the deploy when the callback env var is missing","Cover url_for_oauth_code with a test asserting the redirect_uri param appears in the built URL"],"tags":["oauth","redirect-uri","argumenterror","configuration","koala","facebook"],"backgroundTag":"missing-redirect-uri","analyzedSha":"47d052063ef8b5644fb59e279da0b52687999f55","analyzedAt":"2026-08-23T10:19:03.891Z","schemaVersion":2},"datasetVersion":"2026-08-23T13:39:53.451Z"}