2016-08-16 38 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, 

你所做的一切。嘗試一下!