本文整理汇总了PHP中Hybrid_Auth::authenticate方法的典型用法代码示例。如果您正苦于以下问题:PHP Hybrid_Auth::authenticate方法的具体用法?PHP Hybrid_Auth::authenticate怎么用?PHP Hybrid_Auth::authenticate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hybrid_Auth
的用法示例。
在下文中一共展示了Hybrid_Auth::authenticate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getGoogleLogin
public function getGoogleLogin($auth = NULL)
{
if ($auth == 'auth') {
Hybrid_Endpoint::process();
}
try {
$oauth = new Hybrid_Auth(app_path() . '/config/google_auth.php');
$provider = $oauth->authenticate('Google');
$profile = $provider->getUserProfile();
} catch (exception $e) {
return $e->getMessage();
}
if ($user = User::where('email', '=', $profile->email)->first()) {
Auth::login($user, true);
return Redirect::intended('/');
}
return App::make('frontend\\UserController')->doSignUp(array('email' => $profile->email, 'login' => $profile->identifier, 'password' => "pass1234", 'f_name' => $profile->firstName, 'l_name' => $profile->lastName));
}
示例2: createLoginProviderEntity
/**
* @return LoginProviderEntity
*/
protected function createLoginProviderEntity()
{
$type = $this->getHybridType();
//dump($this->getCallbackUrl());die($this->getCallbackUrl());
$params = array('base_url' => $this->getCallbackUrl(), 'providers' => array($type => $this->getConfig() + array('enabled' => TRUE)));
$hybridauth = new \Hybrid_Auth($params);
if (isset($_REQUEST['hauth_start']) || isset($_REQUEST['hauth_done'])) {
\Hybrid_Endpoint::process();
}
/** @var \Hybrid_User_Profile $user */
$user = $hybridauth->authenticate($this->getHybridType(), $this->authenticationParameters)->getUserProfile();
$ret = new LoginProviderEntity($user->identifier, static::getType());
return $ret;
}
示例3: loginWithSocial
public function loginWithSocial($social_provider, $action = "")
{
// check URL segment
if ($action == "auth") {
// process authentication
try {
Session::set('provider', $social_provider);
Hybrid_Endpoint::process();
} catch (Exception $e) {
// redirect back to http://URL/social/
return Redirect::route('loginWith');
}
return;
}
try {
// create a HybridAuth object
$socialAuth = new Hybrid_Auth(app_path() . '/config/hybridauth.php');
// authenticate with Provider
$provider = $socialAuth->authenticate($social_provider);
// fetch user profile
$userProfile = $provider->getUserProfile();
} catch (Exception $e) {
// exception codes can be found on HybBridAuth's web site
Session::flash('error_msg', $e->getMessage());
return Redirect::to('/login');
}
$this->createOAuthProfile($userProfile);
return Redirect::to('/');
}
示例4: getLoginFacebook
public function getLoginFacebook($auth = NULL)
{
if ($auth == 'auth') {
try {
\Hybrid_Endpoint::process();
} catch (Exception $e) {
return Redirect::to("home");
}
return;
}
$config = array("base_url" => "http://laravel/public/", "providers" => array("Facebook" => array("enabled" => true, "keys" => array("id" => "488919314589569", "secret" => "2b8ab46fece7bef72c48abe0eaa664d0"), "scope" => "public_profile,email", "display" => "popup")));
$oauth = new \Hybrid_Auth($config);
$provider = $oauth->authenticate("Facebook");
$profile = $provider->getUserProfile();
var_dump($profile);
echo "FirstName:" . $profile->firstName . "<br>";
echo "Email:" . $profile->email;
echo "<br><a href='logout'>Logout</a> ";
}
示例5: hybridlogin
/**
* Login using hybrid auth.
*/
function hybridlogin($provider)
{
if (isset($_REQUEST['hauth_start']) || isset($_REQUEST['hauth_done'])) {
Hybrid_Endpoint::process();
exit;
}
$config = array("base_url" => RewriteUtil::getBaseUrl() . "main/hybridlogin?provider=" . $provider, "providers" => array());
if (isset($this->config["facebookAppId"])) {
$config["providers"]["Facebook"] = array("enabled" => true, "trustForwarded" => false, "scope" => "email", "keys" => array("id" => $this->config["facebookAppId"], "secret" => $this->config["facebookSecret"]));
}
$hybridauth = new Hybrid_Auth($config);
try {
$auth = $hybridauth->authenticate($provider);
$profile = $auth->getUserProfile();
$_SESSION["email"] = $profile->email;
$this->redirect();
} catch (Exception $e) {
$this->showLoginForm($e->getMessage());
}
}
示例6: login
public function login(\Hybrid_Auth $hybridAuth, $action = '')
{
try {
switch ($action) {
case 'auth':
\Hybrid_Endpoint::process();
return;
case 'openid-google':
$hybridAuthProvider = $hybridAuth->authenticate('openid', ['openid_identifier' => 'http://www.google.com/accounts/o8/id']);
$hybridAuthUserProfile = $hybridAuthProvider->getUserProfile();
$user = User::firstOrCreate(['authenticator' => 'openid', 'authenticator_credential' => $hybridAuthUserProfile->identifier]);
break;
case 'openid-yahoo':
$hybridAuthProvider = $hybridAuth->authenticate('openid', ['openid_identifier' => 'http://my.yahoo.com']);
$hybridAuthUserProfile = $hybridAuthProvider->getUserProfile();
$user = User::firstOrCreate(['authenticator' => 'openid', 'authenticator_credential' => $hybridAuthUserProfile->identifier]);
break;
case 'google':
$hybridAuthProvider = $hybridAuth->authenticate('google');
$hybridAuthUserProfile = $hybridAuthProvider->getUserProfile();
$user = User::firstOrCreate(['authenticator' => 'openid', 'authenticator_credential' => $hybridAuthUserProfile->identifier]);
break;
case 'facebook':
$hybridAuthProvider = $hybridAuth->authenticate('facebook');
$hybridAuthUserProfile = $hybridAuthProvider->getUserProfile();
$user = User::firstOrCreate(['authenticator' => 'facebook', 'authenticator_credential' => $hybridAuthUserProfile->identifier]);
break;
case 'twitter':
$hybridAuthProvider = $hybridAuth->authenticate('twitter');
$hybridAuthUserProfile = $hybridAuthProvider->getUserProfile();
$user = User::firstOrCreate(['authenticator' => 'twitter', 'authenticator_credential' => $hybridAuthUserProfile->identifier]);
break;
default:
$hybridAuthProvider = $hybridAuth->authenticate('openid', ['openid_identifier' => $action]);
$hybridAuthUserProfile = $hybridAuthProvider->getUserProfile();
$user = User::firstOrCreate(['authenticator' => 'openid', 'authenticator_credential' => $hybridAuthUserProfile->identifier]);
break;
}
\Session::put('userid', $user->id);
// TODO: Return to the index page
} catch (Exception $ex) {
// TODO: Return error to the login form
}
}
示例7: auth
/**
* Prompt the User to authenticate with a social-auth provider
*
* @param $provider_name
* @param null $profile
* @return null
*/
public function auth($provider_name, &$profile = null)
{
$identifier = null;
try {
$provider = $this->hybrid_auth->authenticate($provider_name);
$userProfile = $provider->getUserProfile();
$identifier = $userProfile->identifier;
$profile = $userProfile;
} catch (\Exception $e) {
dd($e->getMessage());
}
return $identifier;
}
示例8: provider_login
public function provider_login()
{
$setting = $this->session->data['social_login_free'];
$server = isset($_SERVER['HTTPS']) ? HTTPS_SERVER : HTTP_SERVER;
if (!isset($setting['base_url_index'])) {
$setting['base_url_index'] = false;
}
if ($setting['base_url_index']) {
$setting['base_url'] = $this->url->link('module/social_login_free/hybridauth', '', 'SSL');
} else {
$setting['base_url'] = $server . 'catalog/model/social_login_free/hybridauth.php';
}
$setting['debug_file'] = DIR_SYSTEM . "logs/social_login_free.txt";
if (isset($this->request->get['provider'])) {
$this->session->data['provider'] = $this->request->get['provider'];
}
$profile = array();
require_once DIR_APPLICATION . "model/social_login_free/hybrid/auth.php";
try {
$hybridauth = new Hybrid_Auth($setting);
$provider = $hybridauth->authenticate($this->session->data['provider']);
//get the user profile
$profile = $provider->getUserProfile();
$this->register($this->session->data['provider'], (array) $profile);
$provider->logout();
} catch (Exception $e) {
switch ($e->getCode()) {
case 0:
$json['error'] = "Unspecified error.";
break;
case 1:
$json['error'] = "Hybriauth configuration error.";
break;
case 2:
$json['error'] = "Provider not properly configured.";
break;
case 3:
$json['error'] = "Unknown or disabled provider.";
break;
case 4:
$json['error'] = "Missing provider application credentials.";
break;
case 5:
$json['error'] = "Authentification failed. " . "The user has canceled the authentication or the provider refused the connection.";
break;
case 6:
$json['error'] = "User profile request failed. Most likely the user is not connected " . "to the provider and he should authenticate again.";
$provider->logout();
case 7:
$json['error'] = "User not connected to the provider.";
$provider->logout();
case 8:
$json['error'] = "Provider does not support this feature.";
break;
}
//echo "Ooophs, we got an error: " . $e->getMessage();
$this->session->data['success'] = $json['error'] . " Ooophs, we got an error: " . $e->getMessage();
$this->response->redirect(urldecode($this->url->link('account/login', '')));
}
}
示例9: _init
function _init()
{
require_once "Hybrid/Auth.php";
if (isset($_GET['_login'])) {
switch ($_GET['_login']) {
case 'tw':
break;
case 'fb':
break;
case 'gp':
break;
}
}
$config = dirname(__FILE__) . '/config.php';
try {
$hybridauth = new Hybrid_Auth($config);
$twitter = $hybridauth->authenticate("Google");
$user_profile = $twitter->getUserProfile();
echo "Hi there! " . $user_profile->displayName;
$twitter->setUserStatus("Hello world!");
$user_contacts = $twitter->getUserContacts();
} catch (Exception $e) {
echo "Ooophs, we got an error: " . $e->getMessage();
}
}
示例10: authenticate
/**
* Authenticate a user based on the request information.
*
* @param Request $request Request to get authentication information from.
* @param Response $response A response object that can have headers added.
* @return array|bool User array on success, false on failure.
*/
public function authenticate(Request $request, Response $response)
{
$fields = $this->_config['fields'];
if (!$request->data($fields['provider'])) {
return $this->getUser($request);
}
$provider = $this->_checkFields($request, $fields);
if (!$provider) {
return false;
}
if ($this->_config['hauth_return_to']) {
$returnTo = Router::url($this->_config['hauth_return_to'], true);
} else {
$returnTo = Router::url(['plugin' => 'ADmad/HybridAuth', 'controller' => 'HybridAuth', 'action' => 'authenticated'], true);
}
$params = ['hauth_return_to' => $returnTo];
if ($provider === 'OpenID') {
$params['openid_identifier'] = $request->data[$fields['openid_identifier']];
}
$this->_init($request);
$adapter = $this->hybridAuth->authenticate($provider, $params);
if ($adapter) {
return $this->_getUser($provider, $adapter);
}
return false;
}
示例11: action_login
public function action_login()
{
//if user loged in redirect home
if (Auth::instance()->logged_in()) {
Auth::instance()->login_redirect();
}
Social::include_vendor();
$user = FALSE;
$config = Social::get();
if ($this->request->query('hauth_start') or $this->request->query('hauth_done')) {
try {
Hybrid_Endpoint::process($this->request->query());
} catch (Exception $e) {
Alert::set(Alert::ERROR, $e->getMessage());
$this->redirect(Route::url('default'));
}
} else {
$provider_name = $this->request->param('id');
try {
// initialize Hybrid_Auth with a given file
$hybridauth = new Hybrid_Auth($config);
// try to authenticate with the selected provider
if ($provider_name == 'openid') {
$params = array('openid_identifier' => 'https://openid.stackexchange.com/');
} else {
$params = NULL;
}
$adapter = $hybridauth->authenticate($provider_name, $params);
if ($hybridauth->isConnectedWith($provider_name)) {
//var_dump($adapter->getUserProfile());
$user_profile = $adapter->getUserProfile();
}
} catch (Exception $e) {
Alert::set(Alert::ERROR, __('Error: please try again!') . " " . $e->getMessage());
$this->redirect(Route::url('default'));
}
//try to login the user with same provider and identifier
$user = Auth::instance()->social_login($provider_name, $user_profile->identifier);
//we couldnt login create account
if ($user == FALSE) {
$email = $user_profile->emailVerified != NULL ? $user_profile->emailVerified : $user_profile->email;
$name = $user_profile->firstName != NULL ? $user_profile->firstName . ' ' . $user_profile->lastName : $user_profile->displayName;
//if not email provided
if (!Valid::email($email, TRUE)) {
Alert::set(Alert::INFO, __('We need your email address to complete'));
//redirect him to select the email to register
$this->redirect(Route::url('default', array('controller' => 'social', 'action' => 'register', 'id' => $provider_name)) . '?uid=' . $user_profile->identifier . '&name=' . $name);
} else {
//register the user in DB
Model_User::create_social($email, $name, $provider_name, $user_profile->identifier);
//log him in
Auth::instance()->social_login($provider_name, $user_profile->identifier);
}
} else {
Alert::set(Alert::SUCCESS, __('Welcome!'));
}
$this->redirect(Session::instance()->get_once('auth_redirect', Route::url('default')));
}
}
示例12: login
public function login()
{
$hybridauth = new Hybrid_Auth($this->config->item('social'));
$provider = ucfirst($this->uri->segment(3));
$adapter = $hybridauth->authenticate('Facebook');
$user_profile = $adapter->getUserProfile();
echo "<pre>";
print_r($user_profile);
echo "</pre>";
}
示例13: login
public function login($network = '')
{
$this->network = $network;
$this->setContentType("text/plain");
$this->setRedirectUrl();
$this->setPopupCallback();
$config = $this->get_hybrid_auth_config();
$hybridauth = new Hybrid_Auth($config);
if ($this->network == 'facebook') {
$this->auth = $hybridauth->authenticate("Facebook");
} elseif ($this->network == 'linkedin') {
$this->auth = $hybridauth->authenticate("LinkedIn");
} elseif ($this->network == 'twitter') {
$this->auth = $hybridauth->authenticate("Twitter");
} elseif ($this->network == 'google') {
$this->auth = $hybridauth->authenticate("Google");
} else {
$this->redirect('/');
}
$is_user_logged_in = $this->auth->isUserConnected();
$this->user = $this->auth->getUserProfile();
$u = new User();
if ($u->checkLogin()) {
$this->setProfile();
} else {
if (!$this->do_login()) {
if ($this->do_register()) {
if ($this->do_login()) {
$this->setProfile();
}
}
}
}
if ($popupCallback = $this->getPopupCallback()) {
$this->setContentType('text/html');
$this->set('popupCallback', $popupCallback);
} else {
$this->externalRedirect($this->getRedirectUrl());
}
}
示例14: getUser
private function getUser($provider)
{
try {
$oauth = new \Hybrid_Auth(app_path('../config/hybridauth.php'));
$providerAuth = $oauth->authenticate($provider);
$profile = $providerAuth->getUserProfile();
$user = User::loginWithSocialNetwork($providerAuth, $profile, $oauth->getSessionData(), true);
$token = $user->setHidden($user->loginHidden);
return ['user' => $user];
} catch (\Exception $e) {
return ['error' => $e->getMessage()];
}
}
示例15: authenticate
/**
* @param string $provider
* @param array|null $params
* @return \Hybrid_Provider_Adapter
*/
public static function authenticate($provider, $params = null)
{
self::init();
$adapter = null;
try {
static::initializeHybridAuth();
$provider = @trim(strip_tags($provider));
$adapter = \Hybrid_Auth::authenticate($provider, $params);
} catch (\Exception $e) {
Logger::info($e);
}
return $adapter;
}