0

I'm extending Laravel Socialiste for a new Oauth provider and having trouble with the simple issue of altering the authorize url.

The url generated by the RedirectResponse has %2C instead of +, e.g., https://mycustomerprovider.com/oauth/authorize?scope=blah%2Cblahagain, for the scopes delimiter and thus fails with the particular provider I'm using, in this example mycustomprovider.

Anyone know how to modify this authorize url to change the %2C to +?

return Socialite::driver('mycustomprovider')->redirect();

If you var_dump(Socialite::driver('mycustomprovider')->redirect()), here's what it contains:

RedirectResponse {#886 ▼
  #targetUrl: "http://"
  +headers: ResponseHeaderBag {#888 ▶}
  #content: """
    <!DOCTYPE html>\n
    <html>\n
        <head>\n
            <meta charset="UTF-8" />\n
            <meta http-equiv="refresh" content="1;url=https://mycustomerprovider.com/oauth/authorize?scope=blah%2Cblahagain" />\n
    \n
            <title>Redirecting to https://mycustomerprovider.com/oauth/authorize?scope=blah%2Cblahagain</title>\n
        </head>\n
        <body>\n
            Redirecting to <a href="https://mycustomerprovider.com/oauth/authorize?scope=blah%2Cblahagain</a>.\n
        </body>\n
    </html>
    """
  #version: "1.0"
  #statusCode: 302
  #statusText: "Found"
  #charset: null
}
tim peterson
  • 23,653
  • 59
  • 177
  • 299

1 Answers1

1

You should use a simple middleware for this

php artisan make:middleware ReplaceMiddleware

In App\Http\Middleware\ReplaceMiddleware.php

public function handle($request, Closure $next, $guard = null)
{
    $response = $next($request);
    $response->setContent(str_replace('%2C','+',$response->getContent()));
    return $response;
}

In your Controller. In __construct method

$this->middleware('replace_response');

In App\Http\Kernel.php. Add to $routeMiddleware array

'replace_response' => \App\Http\Middleware\ReplaceMiddleware::class,

You've done. Try it!

KmasterYC
  • 2,294
  • 11
  • 19