本文整理汇总了PHP中OAuth::consumer方法的典型用法代码示例。如果您正苦于以下问题:PHP OAuth::consumer方法的具体用法?PHP OAuth::consumer怎么用?PHP OAuth::consumer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OAuth
的用法示例。
在下文中一共展示了OAuth::consumer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: RegisterWithGoogle
public function RegisterWithGoogle()
{
$code = Input::get('code');
$googleService = OAuth::consumer('Google');
if (!empty($code)) {
$token = $googleService->requestAccessToken($code);
$result = json_decode($googleService->request('https://www.googleapis.com/oauth2/v1/userinfo'), true);
$user = User::firstOrCreate(array('email' => $result['email']));
if ($user != null) {
$user->nombre = $result['name'];
$user->avatar = $result['picture'];
$user->save();
Auth::login($user, false);
Session::flash('message', "<img src='" . $user->avatar . "' height='70' alt=''> Registrado con Facebook <br> Bienvenido " . $result['name']);
if (Auth::user()->residencia_id == null) {
return Redirect::to("register/completar-registro");
} else {
return Redirect::to("/");
}
} else {
Session::flash('message', "Error al Crear usuario");
return Redirect::to("/");
}
} else {
$url = $googleService->getAuthorizationUri();
return Redirect::to((string) $url);
}
}
示例2: loginWithGoogle
public function loginWithGoogle(Request $request)
{
// get data from request
$code = $request->get('code');
// get google service
$googleService = \OAuth::consumer('Google');
// check if code is valid
// if code is provided get user data and sign in
if (!is_null($code)) {
// This was a callback request from google, get the token
$token = $googleService->requestAccessToken($code);
// Send a request with it
$result = json_decode($googleService->request('https://www.googleapis.com/oauth2/v1/userinfo'), true);
$message = 'Your unique Google user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
echo $message . "<br/>";
//Var_dump
//display whole array.
dd($result);
} else {
// get googleService authorization
$url = $googleService->getAuthorizationUri();
// return to google login url
return redirect((string) $url);
}
}
示例3: twitterAuth
public function twitterAuth($token = NULL, $verify = NULL)
{
// get twitter service
$tw = OAuth::consumer('Twitter');
// check if code is valid
// if code is provided get user data and sign in
if (!empty($token) && !empty($verify)) {
// This was a callback request from twitter, get the token
$token = $tw->requestAccessToken($token, $verify);
// Send a request with it
$result = json_decode($tw->request('account/verify_credentials.json'));
try {
$user = User::where('twitter_id', '=', $result->id)->firstOrFail();
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
//if user is not yet registered we have to store existing twitter id and ask for more details
Session::put('twitterAccount', $result);
throw new UserNotRegisteredException();
}
// login the user
Sentry::login($user);
return $user;
} else {
// get request token
$reqToken = $tw->requestRequestToken();
// get Authorization Uri sending the request token
$url = $tw->getAuthorizationUri(array('oauth_token' => $reqToken->getRequestToken()));
// return to twitter login url
return (string) $url;
}
}
示例4: loginWithFacebook
public function loginWithFacebook()
{
// get data from input
$code = Input::get('code');
// get fb service
$fb = OAuth::consumer('Facebook');
// check if code is valid
// if code is provided get user data and sign in
if (!empty($code)) {
// This was a callback request from facebook, get the token
$token = $fb->requestAccessToken($code);
// Send a request with it
$result = json_decode($fb->request('/me'), true);
$message = 'Your unique facebook user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
echo $message . "<br/>";
//Var_dump
//display whole array().
dd($result);
} else {
// get fb authorization
$url = $fb->getAuthorizationUri();
// return to facebook login url
return Redirect::to((string) $url);
}
}
示例5: getLogin
public function getLogin()
{
if (Input::has('code')) {
return App::make('Lio\\Github\\GithubAuthenticator')->authByCode($this, Input::get('code'));
}
// redirect to the github authentication url
return $this->redirectTo((string) OAuth::consumer('GitHub')->getAuthorizationUri());
}
示例6: login
/**
* Authenticate with github
*/
public function login()
{
// Redirect from Github
if (Input::has('code')) {
return App::make('Phphub\\Github\\GithubAuthenticator')->authByCode($this, Input::get('code'));
}
// redirect to the github authentication url
return Redirect::to((string) OAuth::consumer('GitHub')->getAuthorizationUri());
}
示例7: login
public function login()
{
$fb = OAuth::consumer('Facebook');
$code = Input::get('code');
if (!empty($code)) {
$FBToken = $fb->requestAccessToken($code)->getAccessToken();
$_SESSION['FBToken'] = $FBToken;
return Redirect::to('/');
} else {
$url = $fb->getAuthorizationUri();
return Response::make()->header('Location', (string) $url);
}
}
示例8: facebookpages
public function facebookpages()
{
$code = Input::get('code');
$fb = OAuth::consumer('Facebook');
if (!empty($code)) {
$token = $fb->requestAccessToken($code);
$a = $token->getAccessToken();
$result = json_decode($fb->request('/me/accounts'), true);
$pid = $this->savePages($result);
return Redirect::to('/pages')->withCookie(Cookie::make('pid', $pid, 10));
} else {
$url = $fb->getAuthorizationUri();
return Redirect::to((string) $url);
}
}
示例9: _getUser
private function _getUser()
{
$fb = OAuth::consumer('Facebook');
if (Cookie::get('uid')) {
$accessToken = $this->_getAccessTokenByUser(Cookie::get('uid'));
if ($accessToken) {
$token = new OAuth\OAuth2\Token\StdOAuth2Token();
$token->setAccessToken($accessToken);
$token->setEndOfLife(time());
$fb->getStorage()->storeAccessToken('Facebook', $token);
$user = json_decode($fb->request('/me'), true);
$user['access_token'] = $accessToken;
return $user;
}
}
return false;
}
示例10: getVklogin
public function getVklogin()
{
$code = Input::get('code');
//OAuth::setHttpClient('CurlClient');
$vk = OAuth::consumer('Vkontakte', 'http://localhost/study_barter/public/users/vklogin');
//var_dump($code);
if (!empty($code)) {
$token = $vk->requestAccessToken($code);
$result = json_decode($vk->request('users.get?lang=ru&fields=photo_100,photo_200'), true);
$result = $result['response'][0];
//echo "<pre>";
//var_dump($result);
//echo "</pre>";
//die();
if ($user = User::where('vk_id', '=', $result['uid'])->first()) {
//die(var_dump($result));
$member = Member::where('user_id', '=', $user->id)->first();
$member->name = $result['first_name'];
$member->surname = $result['last_name'];
$member->avatar_url = $result['photo_100'];
$member->avatar_url_big = $result['photo_200'];
$member->save();
Auth::login($user);
return Redirect::to('/');
} else {
$user = new User();
$user->vk_id = $result['uid'];
$user->is_active = 1;
$user->save();
$member = new Member();
$member->user_id = $user->id;
$member->name = $result['first_name'];
$member->surname = $result['last_name'];
$member->avatar_url = $result['photo_100'];
$member->avatar_url_big = $result['photo_200'];
$member->save();
Auth::login($user);
Log::info("User [{$result['first_name']}] successfully logged in.");
return Redirect::to('/');
}
} else {
$url = $vk->getAuthorizationUri();
return Redirect::to((string) $url);
}
}
示例11: _remap
public function _remap($method, $args)
{
if ($method == 'linked') {
$this->linked();
return;
}
// Invalid method or no provider = BOOM
if (!in_array($method, array('session', 'callback')) or empty($args)) {
show_404();
}
// Get the provider (facebook, twitter, etc)
list($provider) = $args;
// This provider is not supported by the module
if (!isset($this->providers[$provider])) {
show_404();
}
// Look to see if we have this provider in the db?
if (!($credentials = $this->credential_m->get_active_provider($provider))) {
$this->ion_auth->is_admin() ? show_error('Social Integration: ' . $provider . ' is not supported, or not enabled.') : show_404();
}
// oauth or oauth 2?
$strategy = $this->providers[$provider];
switch ($strategy) {
case 'oauth':
include $this->module_details['path'] . '/oauth/libraries/OAuth.php';
$oauth = new OAuth();
// Create an consumer from the config
$consumer = $oauth->consumer(array('key' => $credentials->client_key, 'secret' => $credentials->client_secret));
// Load the provider
$provider = $oauth->provider($provider);
break;
case 'oauth2':
include $this->module_details['path'] . '/oauth2/libraries/OAuth2.php';
$oauth2 = new OAuth2();
// OAuth2 is the honey badger when it comes to consumers - it just dont give a shit
$consumer = null;
$provider = $oauth2->provider($provider, array('id' => $credentials->client_key, 'secret' => $credentials->client_secret, 'scope' => $credentials->scope));
break;
default:
exit('Something went properly wrong!');
}
// Call session or callback, with lots of handy details
call_user_func(array($this, '_' . $method), $strategy, $provider, $consumer);
}
示例12: loginGithub
public function loginGithub()
{
$code = Input::get('code');
$email = Input::get('email');
$github = OAuth::consumer('GitHub');
if (!empty($email)) {
$user = User::where('email', '=', $email)->first();
if (isset($user)) {
Session::flash('warning', trans('user.register.social.already-exists'));
return Redirect::route('user.register');
}
$user = Sentry::createUser(array('email' => $email, 'password' => md5(time() . uniqid()), 'activated' => true));
UserGitHub::create(array('user_id' => $user->id, 'access_token' => Input::get('access_token'), 'refresh_token' => !empty(Input::get('refresh_token')) ? Input::get('refresh_token') : null, 'end_of_life' => !empty(Input::get('end_of_life')) ? Input::get('end_of_life') : null));
$user = Sentry::findUserByLogin($user->email);
Sentry::login($user, false);
Session::flash('success', trans('user.register.social.success'));
return Redirect::route('home');
} elseif (empty($code)) {
$url = $github->getAuthorizationUri(array('state' => md5(time() . uniqid()), 'redirect_uri' => URL::route('user.login.github')));
return Response::make()->header('Location', (string) $url);
} else {
$token = $github->requestAccessToken($code);
$emails = json_decode($github->request('/user/emails'), true);
if (!is_array($emails) || count($emails) === 0) {
Session::flash('error', trans('user.register.social.no-emails'));
return Redirect::route('user.register');
}
if (count($emails) <= 1) {
$user = User::where('email', '=', $emails[0])->first();
if (isset($user)) {
Session::flash('warning', trans('user.register.social.already-exists'));
return Redirect::route('user.register');
}
$user = Sentry::createUser(array('email' => $emails[0], 'password' => md5(time() . uniqid()), 'activated' => true));
UserGitHub::create(array('user_id' => $user->id, 'access_token' => $token->getAccessToken(), 'refresh_token' => !empty($token->getRefreshToken()) ? $token->getRefreshToken() : null, 'end_of_life' => !empty($token->getEndOfLife()) ? $token->getEndOfLife() : null));
Sentry::login($user, false);
Session::flash('success', trans('user.register.social.success'));
return Redirect::route('home');
}
return View::make('user.social', array('emails' => $emails, 'token' => $token));
}
}
示例13: loginWithFacebook
/**
* Login user with facebook
*
* @return void
*/
public function loginWithFacebook()
{
// get data from input
$code = Input::get('code');
// get fb service
$fb = OAuth::consumer('Facebook');
// check if code is valid
//$user = $this->userRepository->findByFacebookId($code);
// if code is provided get user data and sign in
if (!empty($code)) {
// This was a callback request from facebook, get the token
$token = $fb->requestAccessToken($code);
// Send a request with it
$result = json_decode($fb->request('/me?fields=id,first_name,last_name,name,email'), true);
$user = $this->userRepository->findByFacebookId($result['id']);
if (!$user) {
$user = $this->userRepository->findByEmail($result['email']);
if ($user) {
$user->facebook_id = $result['id'];
$user->save();
} else {
$user = $this->userRepository->newUser();
$user->first_name = $result['first_name'];
$user->last_name = $result['last_name'];
$user->email = $result['email'];
$user->facebook_id = $result['id'];
$user->role_id = 3;
$user->enabled = 1;
$user->user_created_id = 1;
$user->save();
}
}
Auth::login($user, true);
return Redirect::route('app.index')->with(['successMessage' => 'Bienvenido ' . Auth::user()->first_name . ' ' . Auth::user()->last_name . '!', 'showSideBar' => true, 'showProfile' => true]);
} else {
// get fb authorization
$url = $fb->getAuthorizationUri();
// return to facebook login url
return Redirect::to((string) $url);
}
}
示例14: facebookLogin
public function facebookLogin()
{
// get data from input
$code = \Input::get('code');
$redirect = $this->currentURL(\Input::get('url-back'));
// get fb service
$fb = \OAuth::consumer('Facebook');
// check if code is valid
// if code is provided get user data and sign in
if (!empty($code)) {
// This was a callback request from facebook, get the token
$token = $fb->requestAccessToken($code);
// Send a request with it
$result = json_decode($fb->request('/me'), true);
try {
$user = \Sentry::findUserByLogin($result['email']);
if ($user) {
// Log the user in
\Sentry::login($user, false);
return \Redirect::to($redirect);
} else {
$register = \Sentry::createUser(array('first_name' => $result['first_name'], 'last_name' => $result['last_name'], 'username' => $result['username'], 'provider' => 'facebook', 'email' => $result['email'], 'password' => $result['email'], 'activated' => true));
if ($register) {
$login = \Sentry::findUserById($register->id);
// Log the user in
\Sentry::login($login, false);
return \Redirect::to($redirect);
} else {
return \Redirect::to($redirect)->with('message', 'The following errors occurred')->withErrors($validator)->withInput();
}
}
} catch (Cartalyst\Sentry\Users\WrongPasswordException $e) {
echo 'Wrong password, try again.';
}
} else {
// get fb authorization
$url = $fb->getAuthorizationUri();
// return to facebook login url
return \Redirect::to((string) $url);
}
}
示例15: loginOAuth
public function loginOAuth()
{
$code = Input::get("code");
$google = OAuth::consumer("Google");
if (!empty($code)) {
$token = $google->requestAccessToken($code);
$userdata = json_decode($google->request("https://www.googleapis.com/oauth2/v1/userinfo"), true);
$user = User::firstOrNew(array("google_id" => $userdata['id']));
$user->name = $userdata['name'];
$user->email = $userdata['email'];
$user->refresh_token = $code;
//$user->access_token = $;
//dd($token);
//if ($user->name == "Marcin Gordziejewski")
// $user->topaccess = 1;
$user->save();
Auth::loginUsingId($user->id);
return Redirect::route("Home");
} else {
$url = $google->getAuthorizationUri();
return Redirect::to((string) $url);
}
}