2016-08-16 43 views
0

我将Laravel Socialiste扩展为一个新的Oauth提供程序,并且遇到了更改授权URL的简单问题。覆盖Laravel RedirectResponse

RedirectResponse生成的URL具有%2C代替+,例如https://mycustomerprovider.com/oauth/authorize?scope=blah%2Cblahagain,对于范围定界符,因此失败,我使用的特定提供者,在本例mycustomprovider

任何人都知道如何修改此授权网址将%2C更改为+

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

如果var_dump(Socialite::driver('mycustomprovider')->redirect()),这里就是它包含:

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 
} 

回答

1

你应该用一个简单的中间件

php artisan make:middleware ReplaceMiddleware 

应用程序\ HTTP \中间件\ ReplaceMiddleware.php

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

在你的控制器。在__construct方法

$this->middleware('replace_response'); 

在应用\ HTTP \ Kernel.php。加入$ routeMiddleware阵列

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

你所做的一切。尝试一下!