Anyone can help with this issue:
I have simplesamlphp instaled and tested successfully with my IdP and SP.
when I integrated the APP following the doc (step 6) https://simplesamlphp.org/docs/1.5/simplesamlphp-sp I started getting errors I will post bellow.
Here is my autoload.php:
require __DIR__.'/../vendor/autoload.php';
require_once('/var/simplesamlphp/lib/_autoload.php');
$as = new SimpleSAML_Auth_Simple ( 'default-sp' );
if ($as->isAuthenticated ()) {
//die ( 'ok' );
} else {
$param = array (
'ReturnTo' => 'http://10.128.240.181/'
);
$as->requireAuth ( $param );
}
$attributes = $as->getAttributes();
print_r($attributes);
$session = SimpleSAML_Session::getSessionFromRequest();
$session->cleanup();
Error output:
Feb 07 16:52:32 simplesamlphp WARNING [CL0a04f709] The class or interface 'SimpleSAML_Auth_Simple' is now using namespaces, please use 'SimpleSAML\Auth\Simple'.
PHP Notice: Undefined index: REQUEST_URI in /var/simplesamlphp/lib/SimpleSAML/Utils/HTTP.php on line 810
PHP Stack trace:
PHP 1. {main}() /var/www/Cachet/bootstrap/autoload.php:0
PHP 2. SimpleSAML\Auth\Simple->requireAuth() /var/www/Cachet/bootstrap/autoload.php:58
PHP 3. SimpleSAML\Auth\Simple->login() /var/simplesamlphp/lib/SimpleSAML/Auth/Simple.php:103
PHP 4. sspmod_saml_Auth_Source_SP->initLogin() /var/simplesamlphp/lib/SimpleSAML/Auth/Simple.php:161
PHP 5. sspmod_saml_Auth_Source_SP->authenticate() /var/simplesamlphp/lib/SimpleSAML/Auth/Source.php:193
PHP 6. sspmod_saml_Auth_Source_SP->startSSO() /var/simplesamlphp/modules/saml/lib/Auth/Source/SP.php:431
PHP 7. sspmod_saml_Auth_Source_SP->startSSO2() /var/simplesamlphp/modules/saml/lib/Auth/Source/SP.php:336
PHP 8. sspmod_saml_Auth_Source_SP->sendSAML2AuthnRequest() /var/simplesamlphp/modules/saml/lib/Auth/Source/SP.php:298
PHP 9. SAML2\HTTPRedirect->send() /var/simplesamlphp/modules/saml/lib/Auth/Source/SP.php:314
PHP 10. SAML2\Compat\Ssp\Container->redirect() /var/simplesamlphp/vendor/simplesamlphp/saml2/src/SAML2/HTTPRedirect.php:83
PHP 11. SimpleSAML_Utilities::redirectTrustedURL() /var/simplesamlphp/vendor/simplesamlphp/saml2/src/SAML2/Compat/Ssp/Container.php:52
PHP 12. SimpleSAML\Utils\HTTP::redirectTrustedURL() /var/simplesamlphp/lib/SimpleSAML/Utilities.php:276
PHP 13. SimpleSAML\Utils\HTTP::normalizeURL() /var/simplesamlphp/lib/SimpleSAML/Utils/HTTP.php:968
PHP 14. SimpleSAML\Utils\HTTP::getSelfURL() /var/simplesamlphp/lib/SimpleSAML/Utils/HTTP.php:889
****PHP Fatal error: Uncaught SimpleSAML_Error_UnserializableException: Unable to parse base url: http://localhost in /var/simplesamlphp/lib/SimpleSAML/Auth/Source.php:197****
Stack trace:
#0 /var/simplesamlphp/lib/SimpleSAML/Auth/Simple.php(161): SimpleSAML_Auth_Source->initLogin('http://10.128.2...', NULL, Array)
#1 /var/simplesamlphp/lib/SimpleSAML/Auth/Simple.php(103): SimpleSAML\Auth\Simple->login(Array)
#2 /var/www/Cachet/bootstrap/autoload.php(58): SimpleSAML\Auth\Simple->requireAuth(Array)
#3 {main}
thrown in /var/simplesamlphp/lib/SimpleSAML/Auth/Source.php on line 197
Anyone has an idea what could be the cause of this error ? I am a newbie in php and SAML,
I think there are two issues. The first one is:
Feb 07 16:52:32 simplesamlphp WARNING [CL0a04f709] The class or interface 'SimpleSAML_Auth_Simple' is now using namespaces, please use 'SimpleSAML\Auth\Simple'.
It seems you are following an old documentation and using a recent version of SimpleSAMLphp. You will have to use $as = new \SimpleSAML\Auth\Simple('default-sp'); instead of $as = new SimpleSAML_Auth_Simple ( 'default-sp' );
If you are using the latest stable version of SimpleSAMLphp, please follow https://simplesamlphp.org/docs/stable/simplesamlphp-sp
The second issue is
****PHP Fatal error: Uncaught SimpleSAML_Error_UnserializableException: Unable to parse base url: http://localhost in /var/simplesamlphp/lib/SimpleSAML/Auth/Source.php:197****
This is more related to the configuration (This is a wild guess). Can you provide more info on your web server (IIS/Apache/nginx)? I think IIS has some known issues: https://github.com/simplesamlphp/simplesamlphp/issues/540
Related
I've been struggling with this all day. I got brought in to a new app and they require php-cs-fixer to be ran on all files. The project has a .php_cs file in it, but I couldn't get it work in sublime text 3 nor could I get vscode to do it.
The command runs but I get the error:
PHP Fatal error: Uncaught Error: Class 'Symfony\CS\Config\Config' not found in C:\dev\code\.php_cs:63
Stack trace:
#0 C:\Users\Alex\AppData\Roaming\Composer\vendor\friendsofphp\php-cs-fixer\src\Console\ConfigurationResolver.php(933): include()
#1 C:\Users\Alex\AppData\Roaming\Composer\vendor\friendsofphp\php-cs-fixer\src\Console\ConfigurationResolver.php(228): PhpCsFixer\Console\ConfigurationResolver::separatedContextLessInclude('c:\\dev\\code\\Tao...')
#2 C:\Users\Alex\AppData\Roaming\Composer\vendor\friendsofphp\php-cs-fixer\src\Console\ConfigurationResolver.php(625): PhpCsFixer\Console\ConfigurationResolver->getConfig()
#3 C:\Users\Alex\AppData\Roaming\Composer\vendor\friendsofphp\php-cs-fixer\src\Console\ConfigurationResolver.php(458): PhpCsFixer\Console\ConfigurationResolver->getFormat()
#4 C:\Users\Alex\AppData\Roaming\Composer\vendor\friendsofphp\php-cs-fixer\src\Console\Command\FixCommand.php(151): PhpCsFixer\Console\ConfigurationResolver->getReporter()
#5 C:\Users\Alex\AppData\Roaming\Composer\vendor\symfony in C:\dev\code\.php_cs on line 63
Here is the .php_cs file
<?php
$finder = Symfony\Component\Finder\Finder::create()
->files()
->in(__DIR__)
->exclude('vendor')
->exclude('resources/views')
->exclude('storage')
->exclude('public')
->notName("*.txt")
->ignoreDotFiles(true)
->ignoreVCS(true);
$fixers = [
'-psr0',
'-php_closing_tag',
'blankline_after_open_tag',
'double_arrow_multiline_whitespaces',
'duplicate_semicolon',
'empty_return',
'extra_empty_lines',
'include',
'join_function',
'list_commas',
'multiline_array_trailing_comma',
'namespace_no_leading_whitespace',
'no_blank_lines_after_class_opening',
'no_empty_lines_after_phpdocs',
'object_operator',
'operators_spaces',
'phpdoc_indent',
'phpdoc_no_access',
'phpdoc_no_package',
'phpdoc_scalar',
'phpdoc_short_description',
'phpdoc_to_comment',
'phpdoc_trim',
'phpdoc_type_to_var',
'phpdoc_var_without_name',
'remove_leading_slash_use',
'remove_lines_between_uses',
'return',
'self_accessor',
'single_array_no_trailing_comma',
'single_blank_line_before_namespace',
'single_quote',
'spaces_before_semicolon',
'spaces_cast',
'standardize_not_equal',
'ternary_spaces',
'trim_array_spaces',
'no_useless_else',
'unalign_equals',
'unary_operators_spaces',
'whitespacy_lines',
'multiline_spaces_before_semicolon',
'short_array_syntax',
'short_echo_tag',
'concat_with_spaces',
'ordered_use',
];
return Symfony\CS\Config\Config::create()
->fixers($fixers)
->finder($finder)
->setUsingCache(true);
I can run the file manually by going to the cmd prompt and running
php-cs-fixer fix .\Controller.php
And it does what it's supposed to, I think with a default .php_cs file.
Driving me bats. :)
Problem is we were trying to use an older version of php-cs-fixer and it didn't function correctly with our version of php.
Fix was to update to php-cs-fixer v2.*
I have a smarty project, in a php file, I set a abc variable:
$smarty->assign('abc', '123');
now I can use the {$abc} in its corresponding .tpl file.
but now can I use the abc in php file?
I tried $smarty->abc and $smarty->$abc all can not access.
EDIT-01
If I use
$smarty->assign('abc', '1234');
$abc2 = $smarty->get_template_vars('abc');
I will get bellow error:
Fatal error: Uncaught Error: Using $this when not in object context in /Users/sof3/Desktop/smarty-test02/php/test.php:36 Stack trace: #0 {main} thrown in /Users/sof3/Desktop/smarty-test02/php/test.php on line 36
If your Smarty version is version 2. you can use:
$smarty->get_template_vars('abc')
but if your Smarty version is 3, you should use:
$smarty->getTemplateVars('abc')
more detail refer to: https://www.smarty.net/docs/zh_CN/language.syntax.functions.tpl
I used below PHP code based on the GCP documentation here to fetch a list of all the projects which can be accessed with the selected service account.
require __DIR__ . '/vendor/autoload.php';
putenv('GOOGLE_APPLICATION_CREDENTIALS=acc-key.json');
$client = new Google_Client();
$client->setApplicationName('SampleApp');
$client->useApplicationDefaultCredentials();
$client->addScope('https://www.googleapis.com/auth/cloud-platform');
$service = new Google_Service_Bigquery($client);
$optParams = [];
do {
$response = $service->projects->listProjects($optParams);
foreach ($response['projects'] as $project) {
print_r($project);
}
$optParams['pageToken'] = $response->getNextPageToken();
} while ($optParams['pageToken']);
This does work and fetches only one or two projects from a total of 25 projects which can be accessed with this key.
I confirmed the permission on other projects by accessing them while providing an exclusive project name.
Any hints on what could be the missing part?
EDIT: [Based on Mikhail's answer]
I get below error if I change
$service = new Google_Service_Bigquery($client);
to
$service = new Google_Service_CloudResourceManager($client);
I get below error
PHP Notice: Undefined property: Google_Service_CloudResourceManager::$projects in /tests/ListFullSchema.php on line 18
Notice: Undefined property: Google_Service_CloudResourceManager::$projects in /tests/ListFullSchema.php on line 18
PHP Fatal error: Uncaught Error: Call to a member function listProjects() on null in /tests/ListFullSchema.php:18
Stack trace:
#0 {main}
thrown in /tests/ListFullSchema.php on line 18
Fatal error: Uncaught Error: Call to a member function listProjects() on null in /tests/ListFullSchema.php:18
It is because Cloud Resource Manager v2 doesn't have projects.list method, but v1 does. If you'd like to use Google APIs Client Library for PHP for this task, you can download the v1.1.8 and install it following the instructions here. Then you can run the PHP code like in here.
You should use:
$service = new Google_Service_CloudResourceManager($client);
Alternatively, you can use Python, like in the example. The service version is specified inside the code so you don't need custom installations.
After clean install of the Coinbase API for PHP on my Xubuntu 16.04 (composer require coinbase/coinbase) I followed the Coinbase documentation and used the following commands to access my wallet:
<?php
require 'vendor/autoload.php';
use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;
$apiKey = '********';
$apiSecret = '*********';
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);
$accounts = $client->getAccounts();
...
...
The function getAccounts always returns:
PHP Notice: Undefined index: pagination in /home/willem/coinbase/vendor/coinbase/coinbase/src/Mapper.php on line 490
PHP Stack trace:
PHP 1. {main}() /home/willem/coinbase/newfile.php:0
PHP 2. Coinbase\Wallet\Client->getAccounts() /home/willem/coinbase/newfile.php:14
PHP 3. Coinbase\Wallet\Client->getAndMapCollection() /home/willem/coinbase/vendor/coinbase/coinbase/src/Client.php:215
PHP 4. Coinbase\Wallet\Mapper->toAccounts() /home/willem/coinbase/vendor/coinbase/coinbase/src/Client.php:834
PHP 5. Coinbase\Wallet\Mapper->toCollection() /home/willem/coinbase/vendor/coinbase/coinbase/src/Mapper.php:59
PHP Notice: Undefined index: pagination in /home/willem/coinbase/vendor/coinbase/coinbase/src/Mapper.php on line 491
PHP Stack trace:
PHP 1. {main}() /home/willem/coinbase/newfile.php:0
PHP 2. Coinbase\Wallet\Client->getAccounts() /home/willem/coinbase/newfile.php:14
PHP 3. Coinbase\Wallet\Client->getAndMapCollection() /home/willem/coinbase/vendor/coinbase/coinbase/src/Client.php:215
PHP 4. Coinbase\Wallet\Mapper->toAccounts() /home/willem/coinbase/vendor/coinbase/coinbase/src/Client.php:834
PHP 5. Coinbase\Wallet\Mapper->toCollection() /home/willem/coinbase/vendor/coinbase/coinbase/src/Mapper.php:59
Despite the error, the account information is retrieved into $accounts.
Obviously I now use 2>/dev/null but I'd rather not.
Any solution is highly appreciated !
The suggested line of code indeed suppresses the 'notice', as per Alex's comment.
I'm a happy coder again :)
I have an existing, well functional PHP Application. I am looking into an server upgrade which includes moving from PHP5 to PHP7. As far as I can tell from the documentation Smarty3 should be compatible with PHP7. However, when testing this, it turns out that Smarty refuses to compile the templates after the upgrade.
The source of the problem seems to be this line:
$this->smarty->registerPlugin('compiler', 'asset_url', array(&$this, 'asset_url'));
which causes the PHP application to crash like this:
Notice: Array to string conversion in /usr/share/php/smarty3/sysplugins/smarty_internal_templatecompilerbase.php on line 415
Notice: Undefined property: template::$Array in /usr/share/php/smarty3/sysplugins/smarty_internal_templatecompilerbase.php on line 415
Fatal error: Uncaught Error: Function name must be a string in /usr/share/php/smarty3/sysplugins/smarty_internal_templatecompilerbase.php:415
Stack trace:
#0 /usr/share/php/smarty3/sysplugins/smarty_internal_templateparser.php(3585): Smarty_Internal_TemplateCompilerBase->compileTag('asset_url', Array)
#1 /usr/share/php/smarty3/sysplugins/smarty_internal_templateparser.php(4413): Smarty_Internal_Templateparser->yy_r32()
#2 /usr/share/php/smarty3/sysplugins/smarty_internal_templateparser.php(4515): Smarty_Internal_Templateparser->yy_reduce(32)
#3 /usr/share/php/smarty3/sysplugins/smarty_internal_smartytemplatecompiler.php(118): Smarty_Internal_Templateparser->doParse(3, '}')
#4 /usr/share/php/smarty3/sysplugins/smarty_internal_templatecompilerbase.php(283): Smarty_Internal_SmartyTemplateCompiler->doCompile('<!DOCTYPE html>...')
#5 /usr/share/php/smarty3/sysplugins/smarty_internal_template.php(197): Smarty_Internal_TemplateCompilerBase->compileTemplate(Object(Smarty_Internal_Template))
#6 /usr/share/php/smarty3/sysplugins/sm in /usr/share/php/smarty3/sysplugins/smarty_internal_templatecompilerbase.php on line 415
The suspicious line 415 looks like this:
$function = $this->smarty->registered_plugins[$plugin_type][$tag][0];
if (!is_array($function)) {
return $function($new_args, $this);
} elseif (is_object($function[0])) {
return $this->smarty->registered_plugins[$plugin_type][$tag][0][0]->$function[1]($new_args, $this); <- Crash here!
} else {
return call_user_func_array($function, array($new_args, $this));
}
I assume this is some fundamental difference between PHP5 and PHP7 which is biting me, but I can't seem to figure out what it is. Could somebody give me a few pointers to how to sort this out?
If you're using an older version of Smarty, you might want to update. There were some fixes added in 3.1.28 for PHP 7 compatibility that will probably help with this.
See https://github.com/smarty-php/smarty/blob/master/change_log.txt
The explanation of this issue (besides the most common ones like "you have an outdated version") is that in PHP 7 it has been changed the way how code is parsed. In your case:
$this->smarty->registered_plugins[$plugin_type][$tag][0];
is parsed differently in PHP 5 and 7:
PHP 5: $this->smarty->{registered_plugins[$plugin_type][$tag][0]};
PHP 7: ($this->smarty->registered_plugins)[$plugin_type][$tag][0];
You can try fixing these code pieces by placing braces and brackets to indicate the parser what are your exact intentions, but I'd suggest you to upgrade Smarty.