SocialTalkController.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace Themes\kbgolf\pro\app\Http\Controllers\Auth;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Support\Facades\Redirect;
  5. use SocialiteProviders\Apple\Provider;
  6. use Laravel\Socialite\Facades\Socialite;
  7. use Laravel\Socialite\Two\GoogleProvider;
  8. use Laravel\Socialite\Two\FacebookProvider;
  9. use SocialiteProviders\Kakao\KakaoProvider;
  10. use App\Providers\Socialite\OAuth2\DaboryProvider;
  11. use SocialiteProviders\Naver\Provider as NaverProvider;
  12. use Illuminate\Http\Request;
  13. class SocialTalkController extends Controller
  14. {
  15. private $appleTokenService;
  16. private $oauth2Info;
  17. private $target;
  18. public function redirectToProvider($provider)
  19. {
  20. $this->oauth2Info = request('oauth2Info');
  21. // dump($this->oauth2Info);
  22. return $this->setConfig($provider, request('target'))->redirect();
  23. }
  24. public function login($provider)
  25. {
  26. [$this->target, $ssoBrand] = explode('-', $provider);
  27. if ($this->target == 'member') {
  28. if ($ssoBrand == 'naver') {
  29. return Redirect::away('https://talk.naver.com/ct/w5u3g9');
  30. }elseif($ssoBrand == 'kakao'){
  31. return Redirect::away('https://pf.kakao.com/_aAAGj/chat');
  32. }
  33. }
  34. }
  35. public function setConfig($provider, $target)
  36. {
  37. $config = [
  38. 'client_id' => $this->oauth2Info['ClientId'],
  39. 'client_secret' => $this->oauth2Info['ClientSecret'],
  40. 'redirect' => "/social/$target-$provider/callback"
  41. ];
  42. switch ($provider) {
  43. case 'dabory':
  44. $driver = Socialite::buildProvider(DaboryProvider::class, [
  45. 'client_id' => config('app.api.main.ClientId'),
  46. 'client_secret' => config('app.api.main.ClientSecret'),
  47. 'redirect' => $config['redirect']
  48. ]);
  49. break;
  50. case 'facebook':
  51. $driver = Socialite::buildProvider(FacebookProvider::class, $config);
  52. break;
  53. case 'kakao':
  54. $driver = Socialite::buildProvider(KakaoProvider::class, $config);
  55. break;
  56. case 'google':
  57. $driver = Socialite::buildProvider(GoogleProvider::class, $config);
  58. break;
  59. case 'naver':
  60. $driver = Socialite::buildProvider(NaverProvider::class, $config);
  61. break;
  62. case 'apple':
  63. $config['client_secret'] = $this->appleTokenService->generate(
  64. $this->oauth2Info['PrivateKey'],
  65. $this->oauth2Info['ClientId'],
  66. $this->oauth2Info['TeamId'],
  67. $this->oauth2Info['KeyId'],
  68. );
  69. $driver = Socialite::buildProvider(Provider::class, $config);
  70. break;
  71. }
  72. return $driver;
  73. }
  74. }