I'm using lightopenid as the login system for a site and after successful login, I need the user's details like his first name, last name, email and date of birth..
How can I get this information from his openid? Suppose for google, I'm using the authentication url as: https://www.google.com/accounts/o8/id
Then after the validate() method returns 1, I'm redirecting the user to another page in my site. But how can I fetch the details of the user after login ?
FYI, I'm using openid for google, yahoo and aol.
And for facebook, I'm using graph api and for twitter, I'm using twitter oauth. Is there any way of fetching user data with these too? Please suggest.
Just read the manual:
http://code.google.com/p/lightopenid/wiki/GettingMoreInformation
$openid->required = array('namePerson/friendly', 'contact/email');
$openid->optional = array('namePerson/first');
before calling $openid->authUrl()!
Then
$openid->validate();
$userinfo = $openid->getAttributes();
$email = $userinfo['contact/email'];
$firstName = $userinfo['namePerson/first'];
You need to add a parameter to specify that you also want to receive data back from the OpenID request.
I append the following to my OpenID requests to get the email details.
&openid.ns.ax=http%3A%2F%2Fopenid.net%2Fsrv%2Fax%2F1.0&openid.ax.mode=fetch_request&openid.ax.type.email=http://axschema.org/contact/email&openid.ax.required=email
The first part specifies the namespace being used for the extended data.
The second part specifies that we are making a fetch request for the data.
The third part specifies the schema we are using for the email.
And the final part is specifying that we require the email to be returned.
I have tested this with Google and it works fine. I do not have the other accounts, so have not tested it for those.
OAuth and Facebook Graph API will have there own formats, so I am not sure on those ones.
$openid->identity = 'https://www.google.com/accounts/o8/';
// use the following line to obtain the required details. These are the only details that google mail provides.
$openid->required = array('namePerson/friendly', 'contact/email' , 'contact/country/home', 'namePerson/first', 'pref/language', 'namePerson/last');
header('Location: ' . $openid->authUrl());
Seemingly lightopenid provides a method for that:
$openid->validate();
$userinfo = $openid->getAttributes(); // associative array
It returns either SimpleReg or "Attribute Exchange" data. But only if the user agreed to that, I would hope.
Related
I want So I've followed the instructions given on the following page
https://developers.google.com/api-client-library/php/auth/web-app
However, it isn't too clear on how to get the currently signed in user's email id. The current scopes that I've set are for reading the person's profile, his email-id and gmail.readonly (reading all emails).
My question is, say I have the access token, and I've initialized the Google_Client object by setting the access token, how do I get the currently sign-in user's email?
Heh, looks like I just needed to find the proper Google Service. Got this by going through the documentation.
https://developers.google.com/resources/api-libraries/documentation/gmail/v1/php/latest/class-Google_Service_Gmail.html
The code now is:
$gmail = new Google_Service_Gmail($client);
if($client->getAccessCode()) {
$token_data = $client->verifyAccessToken();
$email = $token_data['email'];
}
Also, for some reason, the line with $token_data doesn't seem to work, so I ended up using the REST API to verify the access token. Just replace that line with
$token_data = json_decode(file_get_contents('https://www.googleapis.com/oauth2/v1/tokeninfo?access_token='.urlencode($client->getAccessToken()["access_token"])), true);
So I have a web site where you can login with a username and a password and I would like that with that one login, a session could be generated for converse.js
I've been reading the documentation and the SSO Support and I ended in an example repo for prebinding with php. link
I prepared an object wich should be the model I'll call from my controller, but there are some parameters I'm not sure what they are.
$xmppPrebind = new XmppPrebind('your-jabber-host.tld', 'http://your-jabber-host/http-bind/', 'Your XMPP Clients resource name', false, false);
$xmppPrebind->connect($username, $password);
$xmppPrebind->auth();
$sessionInfo = $xmppPrebind->getSessionInfo(); // array containing sid, rid and jid
The 3rd parameter on the XmppPrebind Constructor 'Your XMPP clients resource name' what is that?
Also when doing the connect function the parameters $username and $password...are those the one I get from my loging form (the one on my website) or some valid user & password pair on the openfire server?
'Your XMPP Clients resource name' = Any name you want, example: myWebChat
"Also when doing the connect function the parameters $username and $password...are those the one I get from my loging form (the one on my website) or some valid user & password pair on the openfire server?" Use prebind to make user autologin to your xmpp server when they login to your website, so the account must valid on xmpp server.
$sessionInfo will have sid rid and jid. Third parameter will be added to jid. You will get something like:
"you#conference.conversejs.orgYour XMPP Clients resource name"
So just set it empty.
I guess only first or third parameters should be set, not both in one time.
For testing purposes, I'd like to get my own full profile datas from LinkedIn API.
So far my code looks like this :
// Fill the keys and secrets you retrieved after registering your app
$oauth = new OAuth("APIKEY", "SECRETKEY");
$oauth->setToken("Token OAuth", "Secret User OAuth");
$oauth->disableSSLChecks();
$params = array();
$headers = array();
$method = OAUTH_HTTP_METHOD_GET;
// Specify LinkedIn API endpoint to retrieve your own profile
$url = "https://api.linkedin.com/v1/people/~:(first-name,last-name,headline,location:(name),skills:(name),educations:(id,school-name,field-of-study))?format=json";
// By default, the LinkedIn API responses are in XML format. If you prefer JSON, simply specify the format in your call
// $url = "https://api.linkedin.com/v1/people/~?format=json";
// Make call to LinkedIn to retrieve your own profile
$oauth->fetch($url, $params, $method, $headers);
$oProfile = json_decode($oauth->getLastResponse());
var_dump($oProfile);
Although I am getting basic profile informations (firstName,headline etc...) but when it comes to full profile informations I get an object with '...' as value everytime, although the informations exist.
I have r_fullprofile ticked in my LinkedIn app interface, so I don't know what I have to do to get these values.
I tried your query with my own account. It looks you issue is with the skills field.
You can see in the LinkedIn API documentation that skills are made up of a skill, and each skill has a name. If you only want the name returned the proper way to ask for it is
skills:(skill:(name)), whereas your request asks for skills:(name).
Here is an updated request for you:
GET https://api.linkedin.com/v1/people/~:(first-name,last-name,headline,location:(name),skills:(skill:(name)),educations:(id,school-name,field-of-study))?format=json
I've been implementing an OAuth login via the Google Identity toolkit in php. I've got as far as getting an authenticated session, the userdata, id, photo etc, which seems to be working more or less ok.
However, I'd like to be able to login using methods that don't rely on redirection on the user's browser (thinking of remote APIs for an application), but bit lost on how to achieve this.
Imagine a request which is something like:
$details = new stdClass();
$details->secret = $config->secret;
$details->client_id = $config->client_id;
$details->app_name = 'my awesome oauth app';
$details->login = array();
$details->login['email'] = 'some google account email # example.com';
$details->login['password'] = '1234';
$token = $this->do_auth($details);
if($token) {
// do stuff, setup cookies, insert token in session table etc
}
I'm using CodeIgniter. Are there any libraries that can do this..? I've seen android apps doing similar things, using custom login forms, so I'm guessing it's achievable in php.
You HAVE to redirect, it's a core essential of the way OAuth works, there is no way around this. That's why there is a redirect_uri parameter.
You only have to do this once though: when the user is logging in and you are requesting an access token. After that, you simply use curl for example to request your data.
I've a php application and successfully create a function to save access tokens and secrets in the database. (It's about sending specific content to their profile)
I want to show them which twitter account they linked to my application. How can I get their twitter user with access token?
Thanks for help.
When you get the access token Twitter also returns a screen_name and user_id variables. You can use those instead of making an additional request to GET account/verify_credentials
Use this instead:
$credentials = $connection->get('account/verify_credentials')
and then to get username, name, and location-
$name = $credentials->name;
$username = $credentials->screen_name;
$location = $credentials->location;