instagram login with hello.js - javascript

I tried to login instagram with hello.js, but it never direct to https://api.instagram.com/oauth/authorize, otherwise it directs to my redirect url immediately, so I cannot get access token. Here's my code:
hello('instagram').login({redirect_uri : instagram_redirect_url,
scope: 'basic, publish'}, function(e){
if(e.error){
}else{
var instagram_access_token =
hello('instagram').getAuthResponse().oauth_token;
var instagram_secret =
hello('instagram').getAuthResponse().oauth_token_secret;
console.log(instagram_access_token);
console.log(instagram_secret);
}
});
hello.init ({
instagram: instagram_client_id
});

I found that I had to change response_type to token:
hello.init(
{
instagram: INSTAGRAM_ID
},
{
redirect_uri: helloOAuthCallback,
popup : {
location: 'no'
},
oauth_proxy : oauthproxy_url,
response_type: 'token'
}
);
Now it works for me.

Related

How to restrict user to display login page if already logged in using Reactjs

I am working on Reactjs and using nextjs framework, I am working on "Login Logout" module and i just want that if user already logged in ( email set in cookie) then he should redirect to "dashboard" page,How can i do this ? I tried with following code but not working for me, giving me error ",Here is my current code
cookies returned from getServerSideProps Reason: undefined cannot be serialized as JSON
export async function getServerSideProps(context: { req: { headers: { cookies: any; }; }; }) {
const cookies = context.req.headers.cookies;
if (cookies && cookies.email) {
// email is present in cookies, so redirect to /dashboard
return {
redirect: {
destination: "/dashboard",
statusCode: 302, // temporary redirect
},
props: {},
};
}
return {
props: {
cookies,
},
};
}
When returning props.cookies from getServerSideProps, you are potentially returning the cookies as undefined. Use '' as the default value if missing.
You can do this:
return {
props: {
cookies: cookies || '',
},
};
You need to parse the cookies and you can get the cookies on the request you don't need the header
const cookies = JSON.parse(context.req.cookies);
if(cookies.email !== undefined)...

Trello API authentication not giving a valid user token if I disconnect

I integrated trello API to my dashboard on symfony 3.4.
When I go to my page for the first time, I have the authorize() function as a popup. When I accept, I have my token and my boards as return. For this case, all is good.
But if I disconnect the current user and come with another, this new user can access to the previous boards. It's like if the token stay the first user how come on the navigator.
Authorize()
Trello.authorize({
name : 'Native Web',
type : 'popup',
expiration: "never",
success: function () { onAuthorizeSuccessful(); },
error: function () { onFailedAuthorization(); },
scope: { write: true, read: true },
});
onAuthorizeSuccessful()
function onAuthorizeSuccessful() {
var token = Trello.token();
Trello.get('/members/me/boards/', successBoards, error);
}
The successBoards function processes the data.
So, do you have an idea? What am I doing wrong?
It's done, i have save the token on cookie. And i call Trello.authorize if the cookie doesn't exist.
I have added persist: false on this function. Like that the token is not save by the trello logic, but by my logic.
If someone is in my case :
Authorize()
Trello.authorize({
name: 'Native Web',
type: 'popup',
persist: false,
expiration: "never",
success: function () {
onAuthorizeSuccessful();
},
error: function () {
onFailedAuthorization();
},
scope: {write: true, read: true},
});
onAuthorizeSuccessful()
function onAuthorizeSuccessful() {
var token = Trello.token();
$.cookie($.cookie('currentLog')+'TokenTrello', token, {expires: 365, secure: false});
loadBoards();
}
loadBoards()
function loadBoards() {
//Get the users boards
$.get('https://api.trello.com/1/members/me/boards?key=' + API_KEY + '&token=' + $.cookie($.cookie('currentLog')+'TokenTrello'), successBoards);
}
Solved for me. Thanks

How to keep logged in session after user is successfully authenticated with his iCloud Account?

This is what I call when my site is loaded:
(function($){})(window.jQuery);
$(document).ready(function () {
window.addEventListener('cloudkitloaded', function() {
CloudKit.configure({
containers: [{
containerIdentifier: 'iCloud.pl.blueworld.fieldservice',
apiToken: 'fc363369412ad6c99020e7e0ed3e2be121008e34534cff7debe1f4f7f829d152',
environment: 'production'
}]
});
var container = CloudKit.getDefaultContainer();
var privateDB = container.privateCloudDatabase;
this.gotoAuthenticatedState = function(userInfo) {
if(userInfo.isDiscoverable) {
//success
} else {
//failure
}
container
.whenUserSignsOut()
.then(this.gotoUnauthenticatedState);
};
this.gotoUnauthenticatedState = function(error) {
//do something of sign out
container
.whenUserSignsIn()
.then(this.gotoAuthenticatedState)
.catch(this.gotoUnauthenticatedState);
};
container.setUpAuth().then(function(userInfo) {
if(userInfo) {
this.gotoAuthenticatedState(userInfo);
} else {
this.gotoUnauthenticatedState();
}
});
});
});
And when I login with success, there correct button appears:
But every time when I refresh the page this button changes:
What to do to keep session and possibility to fetch records until user manually will log out?
How to check if there exists current session (user already authenticated itself) and use it?
Put your token inside an apiTokenAuth object, and add a persist key.
CloudKit.configure({
containers: [{
containerIdentifier: '<your container>',
environment: 'production',
apiTokenAuth: {
apiToken: '<your token>',
persist: true
}
}]
});

Emberjs authentication session not working

I have followed Authentication Tutorial, but running into some issues.
I have a php backend api which resides in another domain, http://rest.api {local development}
The ember js application uses ember-app-kit and connects to the rest api.
When the user submits the login form it sends the username/email with password to one of the route defined in the rest api Session Controller
import AuthManager from 'lms/config/auth_manager';
var SessionNewController = Ember.ObjectController.extend({
attemptedTransition : null,
loginText : 'Log In',
actions: {
loginUser : function() {
var self = this;
var router = this.get('target');
var data = this.getProperties('identity', 'password');
var attemptedTrans = this.get('attemptedTransition');
$.post('http://rest.api/login',
data,
function(results) {
console.log(results.session);
console.log(results.user_id);
AuthManager.authenticate(results.session, results.user_id);
if(attemptedTrans) {
attemptedTrans.retry();
self.set('attemptedTransition', null);
} else {
router.transitionTo('index');
}
}
)
}
}
});
export default SessionNewController;
After receiving the api result in the results variable which looks like this :
Object {success: "user login success", session: "2OmwKLPclC.YhYAT3745467my7t0m2uo", user_id: "1"}
But as soon as I capture the data and send it to the AuthManager which resides in Auth Manager Code
import User from 'lms/models/user';
import Application from 'lms/adapters/application';
var AuthManager = Ember.Object.extend({
init: function() {
this._super();
var accessToken = $.cookie('access_token');
var authUserId = $.cookie('auth_user');
if(!Ember.isEmpty(accessToken) || !Ember.isEmpty(authUserId)) {
this.authenticate(accessToken, authUserId);
}
},
isAuthenticated: function() {
return !Ember.isEmpty(this.get('ApiKey.accessToken')) && !Ember.isEmpty(this.get('ApiKey.user'));
},
authenticate: function(accessToken, userId) {
$.ajaxSetup({
headers: { 'Authorization': 'Bearer ' + accessToken }
});
var user = User.store.find(userId);
console.log(user);
this.set('ApiKey', ApiKey.create({
accessToken: accessToken,
user: user
}));
},
reset: function() {
this.set('ApiKey', null);
$.ajaxSetup({
headers: { 'Authorization': 'Bearer None' }
});
},
apiKeyObserver: function() {
Application.accessToken = this.get('apikey.accessToken');
if (Ember.isEmpty(this.get('ApiKey'))) {
$.removeCookie('access_token');
$.removeCookie('auth_user');
} else {
$.cookie('access_token', this.get('ApiKey.accessToken'));
$.cookie('auth_user', this.get('ApiKey.user.id'));
}
}.observes('ApiKey')
});
export default AuthManager;
I got an error in the console saying
Uncaught TypeError: Object function () {
if (!wasApplied) {
Class.proto(); // prepare prototype...
}
o_defineProperty(this, GUID_KEY, undefinedDescriptor);
o_defineProperty(this, '_super', undefinedDescriptor);
var m = met...<omitted>...e' new.js:23
(anonymous function) new.js:23
jQuery.Callbacks.fire jquery.js:1037
jQuery.Callbacks.self.fireWith jquery.js:1148
done jquery.js:8074
jQuery.ajaxTransport.send.callback jquery.js:8598
It is not able to pass the variables to the imported function.
Finally got this working. The error that was I doing is after extending the Ember.Object.extend() on auth_manager.js, I didn't create the object anywhere. Thats why it couldnt set create a cookie and throwing that error message.
All I had to do was, .create() after extending the object.
Don't know whether it is the right method or not. But it certainly works.

For Twitter: how to get a user's oauth_access_token client-side like facebook, for server side integration

I'm trying to do server-side posting of facebook and twitter posts. So, you click a button: if you're not connected it allows you to connect and opens a dialog overlay to allow you to post a facebook/twitter post; if you are connected it just opens the overlay. Facebook works because I can get all the oAuth keys easily client-side and then pass them to the server. How do I do this in Twitter?
(PS: this is a fully AJAX site so I can't count on page refreshes)
In facebook I do this:
if (FB) {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
$.getJSON(window.page.services + "StoreAuthToken", { type: "facebook", socialId: response.authResponse.userID, authId: response.authResponse.accessToken, expiresInSeconds: response.authResponse.expiresIn }, null);
window.dialogs.loadFacebookOverlay({ href: href, image: image, description: description, socialId: response.authResponse.userID });
} else {
FB.login(function(response) {
if (response.status === 'connected') {
$.getJSON(window.page.services + "StoreAuthToken", { type: "facebook", socialId: response.authResponse.userID, authId: response.authResponse.accessToken, expiresInSeconds: response.authResponse.expiresIn }, null);
window.dialogs.loadFacebookOverlay({ href: href, image: image, description: description, socialId: response.authResponse.userID });
} else { /* user cancled */ }
}, { scope: 'share_item' });
}
});
How do I get the auth token, maybe using twitter #anywhere code?
if (twttr) {
twttr.anywhere(function(T) {
if (T.isConnected()) {
/* how do I get the auth token here? */
window.dialogs.loadTwitter({ href: href, image: image, description: description });
} else {
/* a pop-up is blocked - any way to allow it? */
T.signIn();
}
});
}
Thank you for your help!

Categories

Resources