I never saw this before. Hopefully I can explain it to you that you'll understand it.
My code:
$google2fa = app(Google2FA::class);
$secret = $google2fa->generateSecretKey();
$user = $this->verifyToken('authentication', $request->mail, $secret);
$g2faUrl = $google2fa->getQRCodeUrl(
'name',
$request->mail,
$user['google_authentication']
);
$writer = new Writer(
new ImageRenderer(
new RendererStyle(400),
new ImagickImageBackEnd()
)
);
$qrcode_image = base64_encode($writer->writeString($g2faUrl));
return view('auth.register.admin.index', ['qrcode' => '', 'secret' => $user['google_authentication']]);
Above you see the array variable: $user['google_authentication'] on the first part I create a secret token, then I save the secret in the verify method verifyToken().
When I publish this secret on the view, it shows me a different secret then that i saved. But the weird part is, when I place a var_dump() in the code, then the secret in the view is the same as I saved.
The verify method just do a simple post api request to my middleware where I save the secret under the user, nothing special.
What is wrong in here?
The view doesn't load twice, I already checked Laravel debug bar
And why does it hold the value of the variable ($user['google_authentication']) when I use var_dump() in the code.
Related
I need to change the request parameter i.e. email, and then attempt login with the new email.
What I am trying:
$user_handle = $request->email;
$gook = Gookarma::where('handle', '=', $user_handle)->firstOrFail();
$acc = Account::find($gook->karmable_id);
$request->email = $acc->email;
if ($this->attemptLogin($request)) {
return $this->sendLoginResponse($request);
}
But it doesn't update the request, and login attempt goes with the previous email field input.
Previous email I'm pulling up from API.
I tried with request->all() but when attempt login after the request update, it displays an error.
You could try something like this:
$request->merge(['email' => $acc->email]);
you can use merge method :
$request->merge([
'email' =>$acc->email,
]);
or you can build an array to replace the entire request input like:
$arrayToReplace=$request->all();
$arrayToReplace['email']=$acc->email;
and then use replace method:
$request->replace($arrayToReplace);
if neither of the above ways did not work, try making a request your self:
$array=$request->all();
$array['email']=$acc->email;
$req = new Request([$array]);
then use the new request for your operations.
Creating a new variable of Request instance and assigning email and password from the previous request variable to the new variable worked for me.
$req = new Request([$request]);
$req['email']=$acc->email;
$req['password'] = $request->password;
I'm trying out the ActiveCollab API for my first time. I had to use StackOveflow to figure out how to get the API token since the docs don't tell me this.
Below is my code:
/* GET INTENT */
$url = 'https://my.activecollab.com/api/v1/external/login';
$fields = array(
'email' => "email#email.com",
'password' => "****"
);
$intent = curl_post_connector($url, $fields);
$intent = $intent->user->intent;
/* GET TOKEN */
$url = 'https://app.activecollab.com/my_app_id/api/v1/issue-token-intent';
$fields = array(
'intent' => $intent,
'client_name' => 'My App Name',
'client_vendor' => 'My Company Name'
);
$token = curl_post_connector($url, $fields);
$token = $token->token;
Everything above works and get's the token properly. What I find really weird is that I have to use API v1 to get this, and the docs on ActiveCollab's site don't mention any URL for API v5. It seems like this is the approach everything is taking here on StackOverflow.
Now with the token, I try to get my list of projects:
/* GET PROJECT */
$url = 'https://app.activecollab.com/my_app_id/api/v1/users';
$headers = array (
"X-Angie-AuthApiToken" => $token
);
$projects = curl_get_connector($url, $headers);
var_dump($projects);
But this does not work. There is no error returned - it instead returns an array of languages for some reason! I don't want to paste the massive json object here, so instead I'll link you to a photo of it: https://www.screencast.com/t/7p5JuFB4Gu
UPDATE:
When attempting to use the SDK, it works up until I try getting the token (which is just as far as I got without the SDK). I'm getting Server Error 500, and when looking at the logs, it says:
/home/working/public_html/ac/index.php(21): ActiveCollab\SDK\Authenticator\Cloud->issueToken(123456789)
#1 {main}
thrown in /home/working/public_html/ac/SDK/Authenticator/Cloud.php on line 115
This is line 115 of Cloud.php:
throw new InvalidArgumentException("Account #{$account_id} not loaded");
I honestly don't think I did anything wrong... there must be something wrong with my account ID.
Just for kicks, I commented out that line, and the error disappears and the page loads fine - except now I have no token...
Given that I have a WHMCS addon that I call 'my_addon'. I created the main addon file 'my_addon.php' which does contain nothing than:
<?php
function my_addon_clientarea($vars) {
$client = null;
return array(
'pagetitle' => 'My Addon',
'breadcrumb' => array('index.php?m=my_addon'=>'My Addon'),
'templatefile' => 'views/myaddon_view',
'vars' => array(
'client' => $client
)
);
}
This does basically work. It does give me my template file, everything is passed through. My question is: How do I get the currently logged in client from within that function?
I didn't find any API method and I can't see any constant which does hold this information.
There must be a way to get the current client within the clientarea? Thanks for your help!
For those who do come after me and have the same problem: it's easy to solve. Turned out, that I just had to think it through... I found the client id to be available in the $_SESSION-variable.
So, if you are looking for the client's id:
<?php
function my_addon_clientarea($vars) {
$clientid = $_SESSION['uid'];
// And so on...
}
The official way to get current user information is:
$currentUser = new \WHMCS\Authentication\CurrentUser;
$user = $currentUser->user();
You can find more information here
Can somebody help me guess out this code..this is just a snippet and I think I included all the codes needed for my question. Actually this code is from hybridAuth. My question is, where does "user_id" from the last line came from? I wanted to know because $_SESSION["user"] gives the value of the "id". And I wanted to make another $_SESSION[" "] where I can place the value of email-add from the database (same location where that user_id's "id" exist)
// create an instance for Hybridauth with the configuration file path as parameter
$hybridauth = new Hybrid_Auth( $hybridauth_config );
// try to authenticate the selected $provider
$adapter = $hybridauth->authenticate( $provider );
// grab the user profile
$user_profile = $adapter->getUserProfile();
// load user and authentication models, we will need them...
$authentication = $this->loadModel( "authentication" );
$user = $this->loadModel( "user" );
# 1 - check if user already have authenticated using this provider before
$authentication_info = $authentication->find_by_provider_uid( $provider, $user_profile->identifier );
# 2 - if authentication exists in the database, then we set the user as connected and redirect him to his profile page
if( $authentication_info ){
// 2.1 - store user_id in session
$_SESSION["user"] = $authentication_info["user_id"];
The call to $authentication->find_by_provider_uid() returns an associative array, one key of which is user_id.
To see what other columns are returned by that call:
var_dump($authentication_info);
If the email is among the keys in that array, you may then set it in $_SESSION:
// Store the email into session if it is present in $authentication_info
// Use whatever the appropriate key you find, be it email, email_address, user_email, whatever...
$_SESSION['user_email'] = $authentication_info['email'];
I'm trying to retrieve profile information regarding users who allowed my app to collect data about them (birthday, location etc.). This works fine when, and only when, the user actually visits my app and authenticates with facebook through token exchange.
However, I want to be able to routinely check if the user location hasn't changed, also if a user adds information about himself on FB, I want to "sync" it with my app, so that the information stays the same.
So I save the users access token, and later on, with a cron job I use the token to get his profile:
$user = mysql_query ... <- get data from mysql
and then:
$user_profile = $facebook->api('/'.$user['uid']);
And it works, of course, but all the data I want from using extended permissions - just doesn't show up!
Is the the curse of the offline_access disabling? Or do I need to use a different way of obtaining such data. I tried adding ?fields=birthday and etc. on the end of the query, but it still doesn't work.
Not sure if this is what you meant by 'offline_access disabling' however Facebook are deprecating offline_access as you can see in the roadmap:
http://developers.facebook.com/roadmap/
You can read more information on the deprecation here:
http://developers.facebook.com/roadmap/offline-access-removal/
Also, are you correctly setting the access token received from the database?
$facebook->setAccessToken($user['access_token']);
Found out how to accomplish this - the access token has to be passed as an additional parameter on the api queries, like such:
$user_profile = $facebook->api('/'.$user['uid'].'', array('access_token' => $session['access_token']));
In case anyone wonders onto this page, here is a way to use saved access tokens, to access full information about the user you want, without having to authenticate:
<?
require "facebook.php";
$facebook = new Facebook(array(
'appId' => your_app_id,
'secret' => your_app_secret
));
// get the saved user details
$user = mysql_fetch_assoc(mysql_query('SELECT * FROM `facebook_tokens` WHERE `id` = "1"'));
$session = array(
'access_token' => $user['access_token'],
'secret' => $user['secret'],
'session_key' => $user['session_key'],
'uid' => $user['uid']
);
$sig = '';
foreach($session as $key => $value) {
$sig .= implode('=', array($key, $value));
}
$session['sig'] = md5($sessionStr.'Your App Secret');
$facebook->setSession($session, false);
$user_profile = $facebook->api('/'.$session['uid'], array('access_token' => $session['access_token']));
echo '<pre>';
print_r($user_profile);
echo '</pre>';
?>