open id or single sign on like stackoverflow - php

I m very impressed with the idea of stackoverflow, the way they provide the options to login to the users is very easy for any user. And if I have to do the same thing in my website then how its going to be. what will be the coding structure and coding snippets for the same in php , mysql and javascript (ajax).
https://stackoverflow.com/users/login

Here is a simple OpenID class, that provides some functionality. First, you need to register an OpenID URL, then, simply type your OpenID in form in openid-example.php and it will redirect you to your OpenID provider, just as you do it on StackOverflow. Then, after your confirmation, it will redirect you back with some personal information, which you can use on your site.

Related

How to use Google Login without plugin in WordPress?

I have seen some websites who allows their users to register or log in with social networks. I want to do the same for my WordPress blog, I already started to learn about it, but the more I read, the more I am getting confused. That's why I am asking for the help here.
I want to allow my WordPress blog users to log in or register with Google. I Have already created Client ID, Email address, Client secret, Redirect URIs, JavaScript Origins. But I don't know how to use them.
Well using a plugin for this sort of functionality is absolutely recommended, because you dont have to care about the security and other issues. Even seasonal programmers get a bit confused using the OAuth library but to start with checkout this tutorial it is as simple as it can be.
http://www.w3resource.com/API/google-plus/tutorial.php
Either way you will have to still create your own plugin and once you get the data from the google api, you will have to use a function like wp_create_user or wp_insert_user to register those users. This is pretty much what a (free) out of box plugin can do for you.

Make Google sign-in use a PHP Session

Right now I'm trying to develop a simple website to demo three kinds of logins: Facebook, Google, and Twitter.
I have gotten both Facebook and Twitter to use PHP Sessions to hold user data so I can reference them on any page (such as showing their name, avatar.)
The site I'm making will only use login to store their basic profile information such as id, name, and email simply as a login feature, it is not necessary to use any higher level features.
However, I can't get Google sign-in to dump its contents into a session, Google insists on using a callback and catching the callback through Javascript functions on the page.
Google doc help for this: https://developers.google.com/+/web/signin/add-button
I'm not really familiar with this, and not sure how to reference a user's data page-to-page without writing a bunch of javascript catch functions, and javascript can't set PHP sessions. Plus, I want to make the three somewhat uniform, so whether they are signed into Twitter, Facebook, or Google, I can just write in PHP
if (isset($_SESSION['USERID']))
{show their info no matter what login because they set the same session fields}
And everything would be happy.
So I would like to know if I can just inject Google Login info into PHP sessions and how I'd go about doing that.
============
A trailing question I have is that I've been scouring help and tutorials for Oauth login for days, and have not really arrived at a better understanding of how to do Oauth in the way that I would just understand and write it. It seems way too complicated and specific to each service to write freehand. And most documentation is an ocean of oh god what are they even talking about. So if someone could trigger my understanding in dumb people words that would be great.
I worked around this problem, my problem and resources in regards to jQuery sign-in can be found here:
Google signin callback - get name and email
Reflection on PHP Versus JQuery
Although Google has an API for PHP, when I found it it looked old and deprecated, with little to no help/documentation. Since I was new to Google's specific login flow and I was intent on basic web language solutions (they are rather dedicated to javascript/jQuery) I followed their jQuery sign-in documentation.
Since all my other login options use PHP it was a bother to make so many exceptions for jQuery.
But, what you can do is leave the callback method in the header on your pages. On login, Google verifies the login info and bounces you back to page, you can sweep the user to the right page in the callback, and you can also use AJAX to inject login information into the database.
The good thing about the jQuery signin is you don't have to keep track of PHP sessions and variables. The bad part is it feels a bit ungainly and inconvenient compared to just talking to the server with PHP.
If interested, see workaround link above.
if ($gClient->getAccessToken()) {
$userProfile = $google_oauthV2->userinfo->get();
//DB Insert
$gUser = new Users();
$gUser->checkUser('google',$userProfile['id'],$userProfile['given_name'],$userProfile['family_name'],$userProfile['email'],$userProfile['gender'],$userProfile['locale'],$userProfile['link'],$userProfile['picture']);
$_SESSION['google_data'] = $userProfile; // Storing Google User Data in Session
var_dump($_SESSION['google_data']);
header("location: account.php");
$_SESSION['token'] = $gClient->getAccessToken();
} else {
$authUrl = $gClient->createAuthUrl();
}

PHP Openid selector try_auth file

I am trying to implement openid selector into my website, I wonder what is the try_auth file that I need for my openid selector to work?
All I want user to login into my website is using only their google account, so could anyone help me out? I have been doing alot of research and I didn't find a successful way of doing so. I am using PHP for my back end development.
Perhaps if someone could help explain how everything works that will be great, as well I didn't plan to use DB to store any user login. I know I have to have a session variable to check in every page whether user have login or not.
openid-selector is just a nice front-end for choosing which OpenID provider to use for signing in.
You also need a library that does the according back-end stuff. In your case this missing file is part of php-openid: https://github.com/openid/php-openid

StackExchange OAuth and OpenID Authentication?

I have been having a goosey around the login functions of stackexchange, and I have noticed that depends on what you click, it adjusts a form with either OAuth information, or OpenID information in the form of the query which submits the form to a script inside of stackexchange, and I was wondering if anyone had the information for how the script would communicate with that particular service and use the returned information to login, as well as fetching additional information about that account from the service.
If anyone has any scripts or snippets, PHP would be preferred.
The Janrain OpenID Libraries are pretty good. They have a few quirks when it comes to extending them, but I think for your purposes they will be fine.
Facebook does NOT do OpenID. For Facebook you will need to use a different library (and that is something I have not done, so I cannot comment on it).

FB js invite friend

This is not duplicate, as it may seam from the title. Continue reading.
So what I want is to create JS script, which would automatically send an invitation to a certain user to become a friend.
How do I approach this?
Basically, user will need to copy my JS code to browser URL bar, which will append JS directly to the Facebook session. (meaning that now I can send POST request on behalf of the user)
Of course, users are aware about the final result. (it is sort of blind-dating what I am thinking to make)
Is this theoretically possible?
Edit: I think the best way to implement something like this is to use Facebook Connect to authenticate users on your site and connect the users that way. Once the users have connected on your site, invite them to connect on Facebook too (by using the method below or just linking to their profile). This way, you're controlling the "meet", like you want, but you're also allowing them to connect on Facebook in a legitimate way.
Give this dialog a shot, and just direct the user to:
http://www.facebook.com/dialog/friends/?id=<USER_ID_TO_BE_ADDED>&app_id&<APP_ID>&redirect_uri=<ADDRESS_IN_YOUR_DOMAIN>
Alternatively, you could simply open a popup with that URL using window.open.
From what you suggested in your question though, it doesn't sound like you wish to use the feature like Facebook intended. From the usage notes:
This feature is intended to help users become friends on Facebook with people that they are connected to in real life. You should not use this feature to encourage users to friend other users that they are not connected to in real life. If your app is found to be encouraging this behavior, your usage of this feature may be disabled.

Categories