protected function prepareForTests()
 {
     parent::prepareForTests();
     Route::enableFilters();
     $this->current_realm = Config::get('app.url');
     $user = User::where('identifier', '=', 'sebastian.marcet')->first();
     $this->be($user);
     Session::start();
     $scope = $this->getScopes();
     $this->client_id = 'Jiz87D8/Vcvr6fvQbH4HyNgwTlfSyQ3x.openstack.client';
     $this->client_secret = 'ITc/6Y5N7kOtGKhg';
     $params = array('client_id' => $this->client_id, 'redirect_uri' => 'https://www.test.com/oauth2', 'response_type' => OAuth2Protocol::OAuth2Protocol_ResponseType_Code, 'scope' => implode(' ', $scope), OAuth2Protocol::OAuth2Protocol_AccessType => OAuth2Protocol::OAuth2Protocol_AccessType_Offline);
     Session::set("openid.authorization.response", IAuthService::AuthorizationResponse_AllowOnce);
     $response = $this->action("POST", "OAuth2ProviderController@authorize", $params, array(), array(), array());
     $status = $response->getStatusCode();
     $url = $response->getTargetUrl();
     $content = $response->getContent();
     $comps = @parse_url($url);
     $query = $comps['query'];
     $output = array();
     parse_str($query, $output);
     $params = array('code' => $output['code'], 'redirect_uri' => 'https://www.test.com/oauth2', 'grant_type' => OAuth2Protocol::OAuth2Protocol_GrantType_AuthCode);
     $response = $this->action("POST", "OAuth2ProviderController@token", $params, array(), array(), array("HTTP_Authorization" => " Basic " . base64_encode($this->client_id . ':' . $this->client_secret)));
     $status = $response->getStatusCode();
     $this->assertResponseStatus(200);
     $content = $response->getContent();
     $response = json_decode($content);
     $access_token = $response->access_token;
     $refresh_token = $response->refresh_token;
     $this->access_token = $access_token;
 }
示例#2
0
 /**
  * Get the Register violin
  */
 public static function get()
 {
     // create instance
     $v = new self();
     // add custum rules
     $v->addFieldMessages(['mail' => ['max' => Language::get('mail.max'), 'email' => Language::get('mail.email')], 'name' => ['max' => Language::get('name.max')], 'pass' => ['max' => Language::get('pass.max')], 'pass_confirm' => ['matches' => Language::get('pass_confirm.matches')]]);
     // add unique validation
     $v->addRuleMessage('unique', Language::get('unique'));
     $v->addRule('unique', function ($val, $in, $args) {
         return (int) User::where('mail', $val)->where('id', '!=', $args[0])->count() === 0;
     });
     // add unique validation
     $v->addRuleMessage('num', Language::get('num'));
     $v->addRule('num', function ($val, $in, $args) {
         if ($val == '') {
             return true;
         }
         return (int) strlen(preg_replace('![^0-9]+!', '', $val)) === $args[0];
     });
     // add unique validation
     $v->addRuleMessage('capitals', Language::get('capitals'));
     $v->addRule('capitals', function ($val, $in, $args) {
         if ($val == '') {
             return true;
         }
         return (int) strlen(preg_replace('![^A-Z]+!', '', $val)) === $args[0];
     });
     // return instance
     return $v;
 }
 protected function prepareForTests()
 {
     parent::prepareForTests();
     App::singleton(UtilsServiceCatalog::ServerConfigurationService, 'StubServerConfigurationService');
     //Route::enableFilters();
     $this->current_realm = Config::get('app.url');
     $user = User::where('identifier', '=', 'sebastian.marcet')->first();
     $this->be($user);
     Session::start();
 }
 public function process(User $user)
 {
     //check if we have a current openid message
     $msg = $this->memento_service->getCurrentRequest();
     if (!is_null($msg) && $msg->isValid() && OpenIdAuthenticationRequest::IsOpenIdAuthenticationRequest($msg)) {
         //check if current user is has the same identity that the one claimed on openid message
         $auth_request = new OpenIdAuthenticationRequest($msg);
         if (!$auth_request->isIdentitySelectByOP()) {
             $claimed_id = $auth_request->getClaimedId();
             $identity = $auth_request->getIdentity();
             $current_identity = $this->server_configuration->getUserIdentityEndpointURL($user->getIdentifier());
             //if not return fail ( we cant log in with a different user that the one stated on the authentication message!
             if ($claimed_id !== $current_identity && $identity !== $current_identity) {
                 Log::warning(sprintf(OpenIdErrorMessages::AlreadyExistSessionMessage, $current_identity, $identity));
                 throw new AuthenticationException(sprintf(OpenIdErrorMessages::AlreadyExistSessionMessage, $current_identity, $identity));
             }
         }
     }
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     //get all users
     $users = User::all();
     // and update new field external_identifier with member id
     foreach ($users as $user) {
         $email = $user->external_id;
         $member = Member::where('Email', '=', $email)->first();
         if (!is_null($member)) {
             $user->external_identifier = $member->ID;
             $user->save();
         }
     }
 }
示例#6
0
 public function addUserAction(IOpenIdUser $user, $ip, $user_action, $realm = null)
 {
     try {
         $action = new UserAction();
         $action->from_ip = $ip;
         $action->user_action = $user_action;
         $action->realm = $realm;
         $user = User::find($user->getId());
         if ($user) {
             $user->actions()->save($action);
             return true;
         }
         return false;
     } catch (Exception $ex) {
         Log::error($ex);
         return false;
     }
 }
 public function testCheckSetupOAuth2ExtensionSubView()
 {
     //set login info
     $user = User::where('identifier', '=', 'sebastian.marcet')->first();
     Auth::login($user);
     $scope = array(sprintf('%s/resource-server/read', $this->current_realm), sprintf('%s/resource-server/read.page', $this->current_realm), sprintf('%s/resource-server/write', $this->current_realm), sprintf('%s/resource-server/delete', $this->current_realm), sprintf('%s/resource-server/update', $this->current_realm), sprintf('%s/resource-server/update.status', $this->current_realm), sprintf('%s/resource-server/regenerate.secret', $this->current_realm));
     $params = array(OpenIdProtocol::param(OpenIdProtocol::OpenIDProtocol_NS) => OpenIdProtocol::OpenID2MessageType, OpenIdProtocol::param(OpenIdProtocol::OpenIDProtocol_Mode) => OpenIdProtocol::SetupMode, OpenIdProtocol::param(OpenIdProtocol::OpenIDProtocol_Realm) => "https://www.test.com/", OpenIdProtocol::param(OpenIdProtocol::OpenIDProtocol_ReturnTo) => "https://www.test.com/oauth2", OpenIdProtocol::param(OpenIdProtocol::OpenIDProtocol_Identity) => "http://specs.openid.net/auth/2.0/identifier_select", OpenIdProtocol::param(OpenIdProtocol::OpenIDProtocol_ClaimedId) => "http://specs.openid.net/auth/2.0/identifier_select", OpenIdOAuth2Extension::paramNamespace() => OpenIdOAuth2Extension::NamespaceUrl, OpenIdOAuth2Extension::param(OpenIdOAuth2Extension::ClientId) => $this->oauth2_client_id, OpenIdOAuth2Extension::param(OpenIdOAuth2Extension::Scope) => implode(' ', $scope), OpenIdOAuth2Extension::param(OpenIdOAuth2Extension::State) => uniqid());
     $response = $this->action("POST", "OpenIdProviderController@endpoint", $params);
     $this->assertResponseStatus(302);
     $content = $response->getContent();
 }
示例#8
0
 /**
  * @return bool
  * @throws \Auth\AuthException
  */
 public function loginSocial()
 {
     if (!$this->session->token) {
         if (isset($_POST['token']) && isset($_SERVER['HTTP_HOST'])) {
             $s = file_get_contents('http://ulogin.ru/token.php?token=' . $_POST['token'] . '&host=' . $_SERVER['HTTP_HOST']);
             $result = json_decode($s, true);
             $userProviders = UserProviders::find(['uid' => $result['uid']])[0];
             $auth = new A();
             $auth->user_id = $userProviders->user_id;
             $auth->provider_id = $userProviders->provider_id;
             $auth->token = uniqid();
             $auth->save();
             $this->session->token = $auth->token;
             $this->session->user = User::find(['id' => $auth->user_id])[0];
             return true;
         }
     } else {
         throw new AuthException('You are already logged in!');
     }
 }
示例#9
0
文件: ajax.php 项目: Torredo/aliev
        if (empty($password1)) {
            $this->setFieldError("password1", "Enter the password");
            return;
        }
        if (empty($password2)) {
            $this->setFieldError("password2", "Confirm the password");
            return;
        }
        if ($password1 !== $password2) {
            $this->setFieldError("password2", "Confirm password is not match");
            return;
        }
        $user = new Auth\User();
        try {
            $new_user_id = $user->create($username, $password1);
        } catch (\Exception $e) {
            $this->setFieldError("username", $e->getMessage());
            return;
        }
        $user->authorize($username, $password1);
        $this->message = sprintf("Hello, %s! Thank you for registration.", $username);
        $this->setResponse("redirect", "callback.php");
        $this->status = "ok";
    }
}
$ajaxRequest = new AuthorizationAjaxRequest($_REQUEST);
if (\Auth\User::isAuthorized() != false) {
    header('Location: ../pages/add_product.php');
} else {
    $ajaxRequest->showResponse();
}
 /**
  * @param User $u
  * @return bool
  */
 public function add(User $u)
 {
     return $u->Save();
 }
示例#11
0
 /**
  * Set user info
  *
  * @param  integer $id default 0
  *
  * @return mixed
  */
 public static function get($id = 0)
 {
     // check id is valid
     if ((int) $id === 0) {
         // check if user login
         if (!Session::has(Config::get(Config::SESSION_NAME))) {
             // return on false id
             return false;
         }
         // Get user id
         $id = Session::get(Config::get(Config::SESSION_NAME));
     }
     // Get the user
     return User::where('id', $id)->take(1)->first();
 }
示例#12
0
 private function seedTestUsersAndClients()
 {
     $resource_server = ResourceServer::first();
     // create users and clients ...
     User::create(array('identifier' => 'sebastian.marcet', 'external_identifier' => 13867, 'last_login_date' => gmdate("Y-m-d H:i:s", time())));
     $user = User::where('identifier', '=', 'sebastian.marcet')->first();
     OpenIdTrustedSite::create(array('user_id' => $user->id, 'realm' => 'https://www.test.com/', 'policy' => IAuthService::AuthorizationResponse_AllowForever));
     Client::create(array('app_name' => 'oauth2_test_app', 'app_description' => 'oauth2_test_app', 'app_logo' => null, 'client_id' => 'Jiz87D8/Vcvr6fvQbH4HyNgwTlfSyQ3x.openstack.client', 'client_secret' => 'ITc/6Y5N7kOtGKhg', 'client_type' => IClient::ClientType_Confidential, 'application_type' => IClient::ApplicationType_Web_App, 'user_id' => $user->id, 'rotate_refresh_token' => true, 'use_refresh_token' => true));
     Client::create(array('app_name' => 'oauth2.service', 'app_description' => 'oauth2.service', 'app_logo' => null, 'client_id' => '11z87D8/Vcvr6fvQbH4HyNgwTlfSyQ3x.openstack.client', 'client_secret' => '11c/6Y5N7kOtGKhg', 'client_type' => IClient::ClientType_Confidential, 'application_type' => IClient::ApplicationType_Service, 'user_id' => $user->id, 'rotate_refresh_token' => true, 'use_refresh_token' => true));
     Client::create(array('app_name' => 'oauth2_test_app_public', 'app_description' => 'oauth2_test_app_public', 'app_logo' => null, 'client_id' => 'Jiz87D8/Vcvr6fvQbH4HyNgwKlfSyQ3x.openstack.client', 'client_secret' => null, 'client_type' => IClient::ClientType_Public, 'application_type' => IClient::ApplicationType_JS_Client, 'user_id' => $user->id, 'rotate_refresh_token' => false, 'use_refresh_token' => false));
     Client::create(array('app_name' => 'oauth2_test_app_public_2', 'app_description' => 'oauth2_test_app_public_2', 'app_logo' => null, 'client_id' => 'Jiz87D8/Vcvr6fvQbH4HyNgwKlfSyQ2x.openstack.client', 'client_secret' => null, 'client_type' => IClient::ClientType_Public, 'application_type' => IClient::ApplicationType_JS_Client, 'user_id' => $user->id, 'rotate_refresh_token' => false, 'use_refresh_token' => false));
     Client::create(array('app_name' => 'resource_server_client', 'app_description' => 'resource_server_client', 'app_logo' => null, 'client_id' => 'resource.server.1.openstack.client', 'client_secret' => '123456789', 'client_type' => IClient::ClientType_Confidential, 'application_type' => IClient::ApplicationType_Service, 'resource_server_id' => $resource_server->id, 'rotate_refresh_token' => false, 'use_refresh_token' => false));
     $client_confidential = Client::where('app_name', '=', 'oauth2_test_app')->first();
     $client_public = Client::where('app_name', '=', 'oauth2_test_app_public')->first();
     $client_service = Client::where('app_name', '=', 'oauth2.service')->first();
     //attach scopes
     $scopes = ApiScope::get();
     foreach ($scopes as $scope) {
         $client_confidential->scopes()->attach($scope->id);
         $client_public->scopes()->attach($scope->id);
         $client_service->scopes()->attach($scope->id);
     }
     //add uris
     ClientAuthorizedUri::create(array('uri' => 'https://www.test.com/oauth2', 'client_id' => $client_confidential->id));
     //add uris
     ClientAllowedOrigin::create(array('allowed_origin' => 'https://www.test.com/oauth2', 'client_id' => $client_confidential->id));
     ClientAuthorizedUri::create(array('uri' => 'https://www.test.com/oauth2', 'client_id' => $client_public->id));
 }
示例#13
0
 public function getUserById($id)
 {
     return User::find($id);
 }