Authenticating app with koajs, passport using google oauth2 - oauth-2.0

I am trying to use Google's sign in api using koa and passport. I'm creating a new GoogleStrategy and that seems to work fine
my issue is in the routes I don't want to redirect the user just yet, I want to send some user's info from my DB to the front end. I've tried passing in a function instead of successRedirect but I am not having any luck. I am new to koa and rethinkDB (using it not sure if it matters in this case). Any ideas would be helpful thanks.
//Routes
router.get('/auth/google', passport.authenticate('google' {session:false, scope:['email','profile'], accessType: 'offline', approvalPrompt: 'force'}));
router.get('/auth/google/callback',
passport.authenticate('google'),{successRedirect:'/home', failureRedirect:'/'}
);

Related

Getting Redirect_URI to work with Google Oauth in Codename one

I am trying to get Google Oauth working with ios in CNO. I have it working fine with a web app, but I can't quite figure out how to have CNO know when to use which client ID or redirect_URI, etc. Below is my code that works fine. The CNO documentation is no help.
Login gc = GoogleConnect.getInstance();
gc.setClientId(web_client_ID);
gc.setRedirectURI("https://google.com");
gc.setClientSecret(client_secret);
doLogin(gc, new GoogleData(), false)
I have a different Client ID for iOS, but where would I put that? How do I change my RedirectURI when I don't want for the OAuth to go to a website, but back to my app?
The client ID is always the native login ID for the device. You can use the isSimulator() method to check if you're running in the simulator to use the web ID.

Thinktecture multiple website connect ( SSO )

I just started exploring Thinktecture becuase i have multiple websites and i want Single Sign On between them . So , i started working on this and i am following this tutorial
Thinktecture tutorial
Every thing works fine following this tutorial , when i added another application in my same project and tried to get access then i stuck because he asked to hit this url in order to get authorized .
http://localhost:52401/connect/authorize?client_id=test&redirect_uri=Http://example.local/&response_type=token&scope=api
and when we hit this he gives us a login page so , how do i suppose to hit this url from my website . I mean from ajax ? or can i redirect user to this url on click of login button . If yes then ok but what happens when user get authenticated and SSo redirect user back to site . Then how can i catch that he is ready to surf my site or not . I mean how to read access_token because access token is in url with # sign like this
http://example.local/#access_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6ImEzck1VZ01Gdjl0UGNsTGE2eUYzekFrZnF1RSIsImtpZCI6ImEzck1VZ01Gdjl0UGNsTGE2eUYzekFrZnF1RSJ9.eyJjbGllbnRfaWQiOiJ0ZXN0Iiwic2NvcGUiOiJhcGkiLCJzdWIiOiJhZG1pbiIsImFtciI6InBhc3N3b3JkIiwiYXV0aF90aW1lIjoxNDMxMDEzMDYxLCJpZHAiOiJpZHNydiIsImlzcyI6InVybjppZGVudGl0eSIsImF1ZCI6InVybjppZGVudGl0eS9yZXNvdXJjZXMiLCJleHAiOjE0MzEwMTY3OTQsIm5iZiI6MTQzMTAxMzE5NH0.GFqRU7U6qWlAY1RdAY__8AQqJidoFiF1KytpZuhX36-3wOUdwB4Y7xLrWkh9yzw9owEajf7QVFB89yjnAMbY82xLK7-HwR2uG0-6TjOL2VNK5f-mLYW4__q4wNtlu0RSxdX1NF3gxcnbn3Iw6nG7YGtXu-wfng_dNXADMmxQK0tG0JDey6QAxZ1129Bh9tmokblJA6Fy5VgZelC-Up1oqsEwbnS3KbRuKtLqlkapjXGpRsI4vTwfnhPtqBu8CN6gnM2EENN3NyENH5CCP7fhqrPwKje9FJ-ly262EKHQxyoN4fTxHhIRZwZ4kzJ42USiFK0xdqbuQMGufjWSAcEGg&token_type=Bearer&expires_in=3600&scope=api
Hey thanks for looking at my tutorial I plan to write part 2 next week that will show how to connect a web app to the SSO. What I tend to do is store the access token in local storage and redirect to thinktecture if there is no access token or if it has expired.
In order to remove the access token from the url you can use javascript like the following.
var ssoParams = window.location.hash;

LinkedIn Oauth error: 'The partner did did not properly implement the authentication protocol' on browser back after signin

We integrated a Rails app with linkedin authentication, using devise and the linkedin gem.
It works fine and able to register/sign in with linkedin, however an odd thing happens when you press 'back' on the browser after signing in/up:
It goes back to linkedin with the same request URL and the error shown is:
The partner did did not properly implement the authentication protocol. in RED
This looks quite bad and we'd like to have a better way of handling this, but no idea where to start; any idea what could trigger this and is there any way we can prevent it?
You will need to build your service for every new request.You might have same access code for diff-2 request.
Try to generate it for every http auth request.
service = new ServiceBuilder()
.provider(LinkedInApi.class)
.apiKey(API_KEY)
.apiSecret(API_SECRET).debug()
.build();

How to use yammer's oauth2 from iOS?

I'm trying to get a iOS client to make use of Yammer's Oauth2 to validate a user. I first tried the GTM-OAuth2 code, but I cannot get it to understand the response from Yammer. It appears that the GTM code is expecting the access_code as a query parameter, where as Yammer is returning it as a uri fragment. I hack he GTM code to see the fragment, but now it appears to be thinking that there is an error because the code and message fields are not in the response from Yammer.
I've also tried to use OAuth2Client api but the problem there is that Yammer does not seem to want to use the redirect_uri I pass to it, so Safari never gets the custom url and therefore never calls back to the app.
Does anyone have a working example of using Yammer's OAuth2?
I would also be interested if anyone has got GTM-OAuth2 to work with Facebook?
Yeah Yammer has a shitty implementation of oAuth. Looks like each service has taken its own implementation of oauth. anyway yammer requires the user to copy a 4-digit code from its website, go back to your service paste that code in your website. Only then you can request for access code.
check this - http://www.tutorialjinni.com/2011/04/yammer-api-example.html (its in php but hope you can get the gist).
Nothing you can do about it but a fun read - Yammer API sucks

Facebook: stay in canvas after oauth callback

I'm working on an app using facebook & oauth. The app lives inside a facebook canvas, and the authentication is done server side. The app is done w/ Ruby on Rails 3.2, using Koala for dealing with the api (and mongodb as backend, for what it's worth), and hosted on heroku.
So, I supply the heroku url as redirect_url for the callback. Which makes the user go out of the canvas after the authentication, and well, I want it to stay inside. I read a few threads about this that suggested I redirect to the canvas url with js once the authentication is done. I did that, but now it seems that my session token is never set, and the user goes through the auth flow every time he tries to see a non-public page (which means he loops on the welcome page, having an "invisible" exchange with facebook each time).
I don't really get what I'm doing wrong here, so any help is welcome. If you need more informations, just ask.
Thanks for your time!
So I found what was my problem : the page my canvas pointed to was a "public" page, and did not handle anything authentication related, meaning it didn't parse the signed_request, or anything else. I ended up setting a special endpoint for the canvas in charge of handling the signed_request logic, and now it works as one would expect.

Resources