2016-08-16 6 views
0

나는 새로운 Oauth 공급자를 위해 Laravel Socialiste을 확장하고 권한 부여 URL을 변경하는 간단한 문제에 어려움을 겪고 있습니다.재정의 Laravel RedirectResponse

RedirectResponse에 의해 생성 된 URL은 범위의 구분을 위해, 예를 들어, %2C 대신 +, https://mycustomerprovider.com/oauth/authorize?scope=blah%2Cblahagain을 가지고 있으며, 따라서이 예 mycustomprovider에서 내가 사용하고 특정 공급자와 함께 실패합니다.

누구나 %2C+으로 변경하는 권한 부여 url을 수정하는 방법을 알고 계십니까?

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

당신은 미들웨어 \ \ 앱 \에서 http이

php artisan make:middleware ReplaceMiddleware 

에 대한 간단한 미들웨어를 사용한다 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 \. 당신이 한

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

$ routeMiddleware 배열에 추가합니다. 시도 해봐!