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
Related
I would like to use the activation email link on localhost. But getting an error auth/invalid-dynamic-link-domain. Here's my configuration which I later pass to sendSignInLinkToEmail method
const actionCodeSettings = {
url: 'exp://192.168.18.30:19001',
handleCodeInApp: true,
iOS: {
bundleId: 'xxx.xxx.xxx'
},
android: {
packageName: 'xxx.xxx.xxx'
installApp: true,
minimumVersion: '12'
},
dynamicLinkDomain: 'http://192.168.18.30:19001/activation'
};
Im not sure If I understand correctly idea of dynamic link...But I can't skip this param
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
}
}]
});
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.
I am using google's API for node.js
https://www.npmjs.com/package/googleapis
I am trying to get an array of all channels which belong to the person
who logged into my website with his google account.
I am using this scope for this matter:
''https://www.googleapis.com/auth/youtube.readonly'
Now here is part of my code:
app.get("/oauthcallback", function(req, res) {
//google redirected us back in here with random token
var code = req.query.code;
oauth2Client.getToken(code, function(err, tokens) { //let's check if the query code is valid.
if (err) { //invalid query code.
console.log(err);
res.send(err);
return;
}
//google now verified that the login was correct.
googleAccountVerified(tokens, res); //now decide what to do with it
});
});
function googleAccountVerified(tokens, res){ //successfully verified.
//user was verified by google, continue.
oauth2Client.setCredentials(tokens); //save tokens to an object
//now ask google for the user's details
//with the verified tokens you got.
youtube.channels.list({
forUsername: true,
part: "snippet",
auth: oauth2Client
}, function (err, response) {
if(err) {
res.send("Something went wrong, can't get your google info");
return;
}
console.log(response.items[0].snippet);
res.send("test");
});
}
Now, in this console.log:
console.log(response.items[0].snippet);
I am getting the same info, no matter what account I am using to log into my website:
{ title: 'True',
description: '',
publishedAt: '2005-10-14T10:09:11.000Z',
thumbnails:
{ default: { url: 'https://i.ytimg.com/i/G9p-zLTq1mO1KAwzN2h0YQ/1.jpg?v=51448e08' },
medium: { url: 'https://i.ytimg.com/i/G9p-zLTq1mO1KAwzN2h0YQ/mq1.jpg?v=51448e08' },
high: { url: 'https://i.ytimg.com/i/G9p-zLTq1mO1KAwzN2h0YQ/hq1.jpg?v=51448e08' } },
localized: { title: 'True', description: '' } }
if I do console.log(response) which is the entire response
I get:
{ kind: 'youtube#channelListResponse',
etag: '"m2yskBQFythfE4irbTIeOgYYfBU/ch97FwhvtkdYcbQGBeya1XtFqyQ"',
pageInfo: { totalResults: 1, resultsPerPage: 5 },
items:
[ { kind: 'youtube#channel',
etag: '"m2yskBQFythfE4irbTIeOgYYfBU/bBTQeJyetWCB7vBdSCu-7VLgZug"',
id: 'UCG9p-zLTq1mO1KAwzN2h0YQ',
snippet: [Object] } ] }
So, two problems here:
1) How do I get an array of owned channels by the logged user,
inside the array I need objects which will represent each channel and basic info like channel name, profile pic.
2) why am I getting the info of some random youtube channel called "True"
Not sure about question one but for question two you get the information for the channel called true because you are asking for it. forUsername: true
I would hope that once you correct this the response may contain more than one channel if the username has more than one.
Just a follow up to the question about basic info.
You dont use Youtube API to get an account's profile information. Instead, try Retrieve Profile Information with G+:
To retrieve profile information for a user, use the people.get API method. To get profile information for the currently authorized user, use the userId value of me.
JavaScript example:
// This sample assumes a client object has been created.
// To learn more about creating a client, check out the starter:
// https://developers.google.com/+/quickstart/javascript
gapi.client.load('plus','v1', function(){
var request = gapi.client.plus.people.get({
'userId': 'me'
});
request.execute(function(resp) {
console.log('Retrieved profile for:' + resp.displayName);
});
});
Google Sign-in for Websites also enables Getting profile information:
After you have signed in a user with Google using the default scopes, you can access the user's Google ID, name, profile URL, and email address.
To retrieve profile information for a user, use the getBasicProfile() method. For example:
if (auth2.isSignedIn.get()) {
var profile = auth2.currentUser.get().getBasicProfile();
console.log('ID: ' + profile.getId());
console.log('Full Name: ' + profile.getName());
console.log('Given Name: ' + profile.getGivenName());
console.log('Family Name: ' + profile.getFamilyName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail());
}
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.