I am new for Ionic. i am developing linkedin Signin for my App. for linkedin Oauth 2 i used cordovaoauth .it goes to linkedin signin page But It gives the error like - Client missing or specified more than once.
my code:
.controller('DashCtrl', function ($scope, $cordovaOauth) {
$scope.linkedinLogin = function () {
$cordovaOauth.linkedin('ClientId', 'clientSecret', ['https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=ClientId&redirect_url=http%3A%2F%2Flocalhost%3A8100%2Fauth%2Flinkedin&state=9898989898', 'r_basicprofile', 'r_emailaddress'], '9898989898').then(function (result) {
console.log("Response Object -> " + JSON.stringify(result));
alert(JSON.stringify(result));
}, function (error) {
console.log("Error -> " + error);
alert(error);
});
Please Help me
You're getting errors because you're including an invalid scope:
https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=ClientId&redirect_url=http%3A%2F%2Flocalhost%3A8100%2Fauth%2Flinkedin&state=9898989898
Remove that from the array and try again.
Best,
Related
Dopey question. I have an object from a library and I want to access it but I just don't get it. Here is the exported object:
exports.listAccounts = function(successCallback,errorCallback)
{
var actionDescriptor = {
method : "GET",
module : "accounts",
action : "accountlist",
useJSON: true,
};
this._run(actionDescriptor,{},successCallback,errorCallback);
};
Now I want to access the account list in code at etListAccounts:
//user sends confirmation code and we get acesss token
app.get('/users/sendcode', function (req, res) {
console.log('verification CODE is '+req.query.vCode);
//end get verification code
et.getAccessToken(req.query.vCode,
function() {
console.log('thread entered getAccessToken function')
et.listAccounts(
function(){console.log('account list success')},
function(error) {
console.log("Error encountered while attempting " +
"to retrieve account list: " +
error);
});
// console.log(accountlist[0]);
},
function(error) {
console.log("Error encountered while attempting " +
"to exchange request token for access token: " +
error);
}
);
})
I've tried this:
et.listAccounts(
function(accountList){console.log('account list success')},
function(error) {
console.log("Error encountered while attempting " +
"to retrieve account list: " +
error);
});
And I've tried this:
et.listAccounts(
function(){accountList},
function(error) {
console.log("Error encountered while attempting " +
"to retrieve account list: " +
error);
});
And I've tried this:
accountList - et.listAccounts(
function(){console.log('account list success')},
function(error) {
console.log("Error encountered while attempting " +
"to retrieve account list: " +
error);
});
This is a nice simple question and I feel foolish for asking it but lots of people can answer it and lots of beginners will find it useful.
From the snippet you shared with us, it appears that you are not importing the module. Please read the documentation here:
https://nodejs.org/docs/latest/api/modules.html#modules_accessing_the_main_module
var imported = require('nameOfModule');
I am using parse javascript SDK, but when I try to handle user registration errors, such like username already taken, the error callback is not triggered.
The code I have is:
signUp: function () {
var self = this;
var errors = this.form.commit({ validate: true });
if(errors) return;
mainapp.showSpinner();
this.model.signUp({
success: function (user) {
console.log(user);
},
error: function (user, error) {
//mainapp.hideSpinner();
console.log('called')
self.errorMessage.html(error);
}
});
},
And the console.log('called) is not triggered, but in console of Chrome I have an javascript error POST https://api.parse.com/1/users 400 (Bad Request)
Any idea how can i catch and handle the error in the error callback?
By checking at the Parse JS sdk documentation, it seems like you miss one parameter when calling sign up function :
user.signUp(null, {
success: function(user) {
// Hooray! Let them use the app now.
},
error: function(user, error) {
// Show the error message somewhere and let the user try again.
alert("Error: " + error.code + " " + error.message);
}
});
https://parse.com/docs/js/guide#users-signing-up
Hope this could help to solve your problem.
My app is in the early development stage. I'm using the latest PhoneGap Build and Facebook Connect plugin. I managed to get the login working - you tap the Login With Facebook button, it switches to the Facebook app, Facebook passes my app an object with the basic login key/token & userID, and then my app tries to reach out for the user's full name and age.
I can't seem to get Facebook to give me any information other than the user's ID and full name. I need the user's age! For some reason, adding a projection isn't working... What's wrong with my code?
var fbLoginSuccess = function (userData) {
facebookConnectPlugin.getAccessToken(function(token) {
if(userData['status'] == 'connected'){
getBasicUserInfo_fb(userData);
}
}, function(err) {
alert("Could not get access token: " + err);
});
}
function getBasicUserInfo_fb(userData){
facebookConnectPlugin.api(userData['authResponse']['userID'] + "/?fields=id,birthday", ["user_birthday"], function (response) {
if (response && !response.error) {
alert("response: " + JSON.stringify(response));
console.log(response);
var user_name = response['name'];
var user_age = response['birthday'];
var user_picture = response['picture'];
}
},
function (error) {
console.log(error);
alert("Failed: " + JSON.stringify(error));
});
}
The Github page (https://github.com/Wizcorp/phonegap-facebook-plugin) says:
Getting a User's Birthday
Using the graph api this is a very simple task:
facebookConnectPlugin.api("<user-id>/?fields=id,email", ["user_birthday"],
function (result) {
alert("Result: " + JSON.stringify(result));
/* alerts:
{
"id": "000000123456789",
"email": "myemail#example.com"
}
*/
},
function (error) {
alert("Failed: " + error);
});
I might be losing my mind but the example on Github is saying how to get the birthday, and the scope is set up to get that, BUT then the parameters are set up to get the email address. Basically all I've done is changed "id,email" to "id,birthday"... What am I doing wrong?!
Apparently I was wrong to have "user_profile" in my initial login request... I guess it only accepts one parameter?
The bad version:
facebookConnectPlugin.login(["public_profile","user_birthday"],
fbLoginSuccess,
function (error) { alert("" + error) }
);
The good version:
facebookConnectPlugin.login(["user_birthday"],
fbLoginSuccess,
function (error) { alert("" + error) }
);
I'm using Azure Mobile Services(AzMS) in VisualStudio JS-Apache Cordova project where I call a AzMS's custom API to insert user data in storage. This very same code I have previously used in a VS web app javascript and there it is working fine.
However here in the cordova project, I get an "unexpected connection failure" error when calling invokeApi. When I try from VS web app, it works fine, which means the custom API service code is good.
Here is my js client code:
azmsClient.login(oAuthProvider).done(function (results) {
console.log("You are now logged in as: " + results.userId);
var theUserAuthId = results.userId;
azmsClient.invokeApi('Users/insert', {
method: 'POST',
body: { userAuthId: theUserAuthId }
}).done(function (response) {
//.... success code
},
function (error) {
console.log("Error: " + err.request.responseText);
//.... error handling
});
},
function (err) {
console.log("Error: " + err.request.responseText);
//.... error handling
});
In the console log, the first log ("You are now logged in as: "..) gets logged, after that the error - unexpected connection failure.
And my azure custom Api code -
var logger = require('../api/logUtils.js').logger;
exports.register = function(api){
api.post('insert', insertUser);
};
/******************************************************************
* #param request
* #param response
*******************************************************************/
function insertUser(request, response){
var user = request.user;
var iM = "api.User.insertUser-";
logger.info( iM + ' called: - ' , request, response, user);
// Data validation
if ( user.level === 'anonymous' ) {
logger.error( iM + 'Anonymous User' );
response.send(500, { error: "Anonymous user." });
}
user.getIdentities({
success: function (identities) {
var req = require('request');
var userId = user.userId.split(':')[1];
var theProvdr = user.userId.split(':')[0];
var reqParams;
logger.info(iM + ': calling getOAuthUserDetails for Identities: - ' , identities);
try {
reqParams = getOAuthUserDetails(userId, identities);
}
catch(err){
logger.error(iM + ': getOAuthUserDetails - ' , err);
response.send(500, { error: err.message });
return;
}
req.get(reqParams, function (err, resp, body) {
if (err) {
logger.error(iM + ': Error calling provider: ', err);
response.send(500, { error: 'Error calling Authentication provider' });
return;
}
if (resp.statusCode !== 200) {
logger.error(iM + ': Provider call did not return success: ', resp.statusCode);
response.send(500, { error: 'Provider call did not return success: ' + resp.statusCode });
return;
}
try {
logger.info(iM + ': success: got User Details body ', body);
var theAppUser = oAuthUser_To_appUser(theProvdr, JSON.parse(body));
addUser(theAppUser, user, {
success: function(userAlreadyExist, userEnt){
logger.info( iM + ': addUser: success', userEnt);
response.send(200, getAppUserEnt(userEnt));
},
error: function(err){
logger.error( iM + ': Error in addUser: ', err);
response.send(500, { error: err.message });
}
});
} catch (err) {
logger.info(iM + ': Error parsing response: ', err);
response.send(500, { error: err.message });
}
});
},
error: function(err){
logger.info(iM + ': error on calling getIdentities: - ' , err);
response.send(500, { error: err.message });
}
});
In the azure service logs, I see no entry logged from the custom api's user.insert function when running from the cordova project, which means the api is got getting called. Like said before, when calling from VS web project, the log records look all good.
(this is somewhat similar to the issue asked here, but not exactly the same.)
I am unable to figure out why its happening so; any idea?
Are you running on a device, emulator, or Ripple. If its Ripple, you have to change the Cross Domain Proxy to 'disabled'. I had similar issues and this seemed to help.
I am using Javascript, webdriverio (v2.1.2) to perform some data extraction from an internal site. The internal site is SSO enabled, so if I have been authenticated on another application, I need not login for this application (common in enterprise intranet applications).
I plan to achieve the below,
Create a client with required capabilities
Pass the required URL
For fun : Print the title of the page
Check if an element exist on the page. If yes, then it's a login page. If not, then it's not login page
login = function (username, password) {
if (!browserClientUtil) {
throw "Unable to load browserClientUtil.js";
}
browserClientUtil
.createClient()
.url(_Url)
.title(function (err, res) {
console.log('Title is: ' + res.value);
}) .isExisting('input#login_button.login_button', function (err, isExisting) {
browserClientUtil.getCurrentClient()
.setValue('input#USER.input', username)
.setValue('input#PASSWORD.input', password)
//.saveScreenshot('ultimatixLoginDetails.png')
.click('input#login_button.login_button')
.pause(100);
handlePostLogin();
});
};
Is this the best way to do? I tried to separate the code for verifying login page in a separate function, it didn't work as everything in webdriver happens as part of callback and I am not sure if I am doing it in a right way.
How do I return from a callback, that will in-turn be the final value returned by that function?
login = function (username, password) {
if (!browserClientUtil) {
throw "Unable to load browserClientUtil.js";
}
browserClientUtil
.createClient()
.url(_Url)
.title(function (err, res) {
console.log('Title is: ' + res.value);
});
if(isThisLoginPage()){
browserClientUtil.getCurrentClient()
.setValue('input#USER.input', username)
.setValue('input#PASSWORD.input', password)
//.saveScreenshot('ultimatixLoginDetails.png')
.click('input#login_button.login_button')
.pause(100);
handlePostLogin();
}
};
isThisLoginPage = function() {
var client = browserClientUtil.getCurrentClient();
if(!client) {
throw "Unable to get reference for current client, hence cannot validate if this is login page.";
}
client.isExisting('input#login_button.login_button', function (err, isExisting) {
if(isExisting) {
return true;
}
});
return false;
};
You can create your own workflow by creating own commands that wrap other ones. For example you can make an own command to login:
browserClientUtil.addCommand("login", function(url, user, pw, cb) {
this.url(url)
.setValue('#username', user)
.setValue('#password', pw)
.submitForm('#loginForm')
.call(cb);
});
This allows you to hide "complex" asynchronous webdriver actions behind a simple function. It is easy to create an powerful toolchain. At the end your test script looks like:
browserClientUtil
.login("http://example.com/login", "john.doe", "testpass")
.getTitle(function(err, title) {
console.log(title);
})
// ...
Cheers