123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
- namespace Themes\kbgolf\pro\app\Http\Controllers\Auth;
- use App\Http\Controllers\Controller;
- use App\Services\CallApiService;
- use Illuminate\Support\Facades\Redirect;
- use SocialiteProviders\Apple\Provider;
- use Laravel\Socialite\Facades\Socialite;
- use Laravel\Socialite\Two\GoogleProvider;
- use Laravel\Socialite\Two\FacebookProvider;
- use SocialiteProviders\Kakao\KakaoProvider;
- use App\Providers\Socialite\OAuth2\DaboryProvider;
- use App\Services\AppleTokenService;
- use SocialiteProviders\Naver\Provider as NaverProvider;
- use Illuminate\Http\Request;
- class SocialTalkController extends Controller
- {
- private $appleTokenService;
- private $callApiService;
- private $oauth2Info;
- private $target;
- public function __construct(CallApiService $callApiService, AppleTokenService $appleTokenService)
- {
- $this->callApiService = $callApiService;
- $this->appleTokenService = $appleTokenService;
- }
- public function redirectToProvider($provider)
- {
- $this->oauth2Info = request('oauth2Info');
- $brandCode = 'member-'.$provider;
- $response = $this->callApiService->callApi([
- 'url' => 'setup-page',
- 'data' => [
- 'PageVars' => [
- 'Query' => "(setup_code = 'sso-client' and brand_code = '{$brandCode}') and is_on_use = '1'",
- 'Limit' => 100
- ]
- ],
- ]);
- if (!empty($response['Page'])) {
- $setupJson = $response['Page'][0]['SetupJson'];
- $setupArray = json_decode($setupJson, true);
- $redirectUri = route('social.login', ['provider' => $brandCode]);
- if (json_last_error() === JSON_ERROR_NONE) {
- $clientId = $setupArray['ClientId'] ?? null;
- // dd($clientId);
- }
- }
- if ($provider == 'naver') {
- $url = 'https://nid.naver.com/oauth2.0/authorize?' . http_build_query([
- 'response_type' => 'code',
- 'client_id' => $clientId,
- 'redirect_uri' => $redirectUri,
- 'state' => csrf_token(),
- ]);
- } elseif ($provider == 'kakao') {
- $url = 'https://kauth.kakao.com/oauth/authorize?' . http_build_query([
- 'response_type' => 'code',
- 'client_id' => $clientId,
- 'redirect_uri' => $redirectUri,
- 'state' => csrf_token(),
- ]);
- }
- return redirect($url);
- }
- public function login($provider)
- {
- [$this->target, $ssoBrand] = explode('-', $provider);
- if ($this->target == 'member') {
- if ($ssoBrand == 'naver') {
- return Redirect::away('https://talk.naver.com/ct/w5u3g9');
- }elseif($ssoBrand == 'kakao'){
- return Redirect::away('https://pf.kakao.com/_aAAGj/chat');
- }
- }
- }
- //사용안함
- public function setConfig($provider, $target)
- {
- $config = [
- 'client_id' => $this->oauth2Info['ClientId'],
- 'client_secret' => $this->oauth2Info['ClientSecret'],
- 'redirect' => "/social/$target-$provider/callback"
- ];
- switch ($provider) {
- case 'dabory':
- $driver = Socialite::buildProvider(DaboryProvider::class, [
- 'client_id' => config('app.api.main.ClientId'),
- 'client_secret' => config('app.api.main.ClientSecret'),
- 'redirect' => $config['redirect']
- ]);
- break;
- case 'facebook':
- $driver = Socialite::buildProvider(FacebookProvider::class, $config);
- break;
- case 'kakao':
- $driver = Socialite::buildProvider(KakaoProvider::class, $config);
- break;
- case 'google':
- $driver = Socialite::buildProvider(GoogleProvider::class, $config);
- break;
- case 'naver':
- $driver = Socialite::buildProvider(NaverProvider::class, $config);
- break;
- case 'apple':
- $config['client_secret'] = $this->appleTokenService->generate(
- $this->oauth2Info['PrivateKey'],
- $this->oauth2Info['ClientId'],
- $this->oauth2Info['TeamId'],
- $this->oauth2Info['KeyId'],
- );
- $driver = Socialite::buildProvider(Provider::class, $config);
- break;
- }
- return $driver;
- }
- }
|