How to resolve Invalid client, OAuth client was not found - oauth-2.0

We are trying to login my worklight hybrid mobile sample application with any google account.
Below screen shot Steps for we creating the google gmail API and creating OAuth 2.0 client IDs
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>LoginSN</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
<!--
<link rel="shortcut icon" href="images/favicon.png">
<link rel="apple-touch-icon" href="images/apple-touch-icon.png">
-->
<link href="jqueryMobile/jquery.mobile-1.4.5.css" rel="stylesheet">
<link rel="stylesheet" href="css/main.css">
<script>window.$ = window.jQuery = WLJQ;</script>
<script src="jqueryMobile/jquery.mobile-1.4.5.js"></script>
<script src="https://apis.google.com/js/client.js?onload=checkAuth"/></script>
<meta name="manifest" content="./google-services.json" />
<script type="text/javascript">
var CLIENT_ID = '<349212001841-2n2vc099on8m0qkms753bdbr60ecnf5o.apps.googleusercontent.com>';
var SCOPES = [ 'https://www.googleapis.com/auth/gmail.readonly' ];
function checkAuth() {
gapi.auth.authorize({
'client_id' : CLIENT_ID,
'scope' : SCOPES.join(' '),
'immediate' : true
}, handleAuthResult);
}
function handleAuthResult(authResult) {
var authorizeDiv = document.getElementById('authorize-div');
if (authResult && !authResult.error) {
authorizeDiv.style.display = 'none';
loadGmailApi();
} else {
authorizeDiv.style.display = 'inline';
}
}
function handleAuthClick(event) {
gapi.auth.authorize({
client_id : CLIENT_ID,
scope : SCOPES,
immediate : false
}, handleAuthResult);
return false;
}
function loadGmailApi() {
gapi.client.load('gmail', 'v1', listLabels);
}
function listLabels() {
var request = gapi.client.gmail.users.labels.list({
'userId' : 'me'
});
request.execute(function(resp) {
var labels = resp.labels;
appendPre('Labels:');
if (labels && labels.length > 0) {
for (i = 0; i < labels.length; i++) {
var label = labels[i];
appendPre(label.name)
}
} else {
appendPre('No Labels found.');
}
});
}
function appendPre(message) {
var pre = document.getElementById('output');
var textContent = document.createTextNode(message + '\n');
pre.appendChild(textContent);
}
</script>
</head>
<body style="display: none;">
<div data-role="page" id="loginPage">
<div data-role="content" style="padding: 15px">
<h1 id="fb-welcome"></h1>
<label for="text">User Name:</label><input type="text" name="text" id="unL">
<label for="text">Password:</label><input type="password" name="text" id="pwdL">
LOGIN
REGISRASTION
via Facebook Login
<!-- via Google Login -->
<!-- via Google Login -->
<!-- via Google Login -->
<div id="authorize-div" >
<span>Authorize access to Gmail API</span>
via Google Login
</div>
</div>
</div>
<div data-role="page" id="dashboardPage">
<div data-role="content" style="padding: 15px">
<a href="#" data-role="button" onclick='Logout();'>LogOut</a>
</div>
</div>
<script src="js/hello.js"></script>
<script src="js/initOptions.js"></script>
<script src="js/main.js"></script>
<script src="js/messages.js"></script>
</body>
</html>
No error in the error log, just the page load error quoted here.
We got error like this screen shot

Error 401 implies that you have an invalid authorization header. The access token you're using is either expired or invalid. Try to refresh the access token using the long-lived refresh token. If this fails, please direct through the OAuth flow. Maybe you also need to recreate the client id in Developers Console. Make sure to have Google+ API enabled.
Check these related SO questions:
Error: invalid_client with Google Apps API OAuth2
If you create OAuth credentials BEFORE you set the support email address in the consent screen, then it appears that you will always get this error, even after setting the support email. I resolved this by setting the support email, and then recreating all necessary OAuth ids in the credentials page.
invalid_client in google oauth2
Set/change your product name, I had this issue until I created a product name as same as project name. The product name can be set in the Consent screen section of the Google Developers Console for your project. Look under APIs & auth in the left navigation and select Consent screen. You need also to set your email address in the box above the product name.

Related

swagger-ui : Add authorization header don't work

I want to add basic authorization in swagger-ui, to test my WS with "Try it out" button. I tried from swagger documentation, and this topic Adding Basic Authorization for Swagger-UI, but no one work. No header is added in request, but in curl command, the basic authorization header is present. If I copy paste this curl command, all is ok.
My swagger-ui version is 2.1.2. I downloaded from github, ant put directly dist folder in static folder of my server.
Here my index.html :
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Sensor API documentation</title>
<link rel="icon" type="image/png" href="images/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="images/favicon-16x16.png" sizes="16x16" />
<link href='css/typography.css' media='screen' rel='stylesheet' type='text/css' />
<link href='css/reset.css' media='screen' rel='stylesheet' type='text/css' />
<link href='css/screen.css' media='screen' rel='stylesheet' type='text/css' />
<link href='css/reset.css' media='print' rel='stylesheet' type='text/css' />
<link href='css/print.css' media='print' rel='stylesheet' type='text/css' />
<script src='lib/jquery-1.8.0.min.js' type='text/javascript'></script>
<script src='lib/jquery.slideto.min.js' type='text/javascript'></script>
<script src='lib/jquery.wiggle.min.js' type='text/javascript'></script>
<script src='lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
<script src='lib/handlebars-2.0.0.js' type='text/javascript'></script>
<script src='lib/underscore-min.js' type='text/javascript'></script>
<script src='lib/backbone-min.js' type='text/javascript'></script>
<script src='swagger-ui.js' type='text/javascript'></script>
<script src='lib/highlight.7.3.pack.js' type='text/javascript'></script>
<script src='lib/marked.js' type='text/javascript'></script>
<script src='lib/swagger-oauth.js' type='text/javascript'></script>
<!-- Some basic translations -->
<!-- <script src='lang/translator.js' type='text/javascript'></script> -->
<!-- <script src='lang/ru.js' type='text/javascript'></script> -->
<!-- <script src='lang/en.js' type='text/javascript'></script> -->
<script type="text/javascript">
$(function() {
// Pre load translate...
if (window.SwaggerTranslator) {
window.SwaggerTranslator.translate();
}
window.swaggerUi = new SwaggerUi({
url : "/swagger/json/SensorAPI.json",
validatorUrl : "",
dom_id : "swagger-ui-container",
supportedSubmitMethods : [ 'get', 'post', 'put', 'delete', 'patch' ],
onComplete : function(swaggerApi, swaggerUi) {
if (window.SwaggerTranslator) {
window.SwaggerTranslator.translate();
}
$('pre code').each(function(i, e) {
hljs.highlightBlock(e)
});
addAuthorization();
},
onFailure : function(data) {
log("Unable to Load SwaggerUI");
},
docExpansion : "none",
apisSorter : "alpha",
showRequestHeaders : false
});
function addAuthorization() {
var username = $('#input_username').val();
var password = $('#input_password').val();
if (username && username.trim() != "" && password && password.trim() != "") {
var basicAuth = new SwaggerClient.PasswordAuthorization(username, password);
window.swaggerUi.api.clientAuthorizations.add('Basic', basicAuth);
log("authorization added: username = " + username + ", password = " + password);
} else {
window.authorizations.remove();
}
}
$('#input_username').change(addAuthorization);
$('#input_password').change(addAuthorization);
// pre-populate on the page using demo account
$('#input_username').val("demo");
$('#input_password').val("demo");
window.swaggerUi.load();
function log() {
if ('console' in window) {
console.log.apply(console, arguments);
}
}
});
</script>
</head>
<body class="swagger-section">
<div id='header'>
<div class="swagger-ui-wrap">
<a id="logo" href="http://swagger.io">swagger</a>
<form id='api_selector'>
<div class='input'>
Username: <input placeholder="username" id="input_username" name="username" type="text" size="10" />
</div>
<div class='input'>
Password: <input placeholder="password" id="input_password" name="password" type="password" size="10" />
</div>
</form>
</div>
</div>
<div id="message-bar" class="swagger-ui-wrap" data-sw-translate> </div>
<div id="swagger-ui-container" class="swagger-ui-wrap"></div>
</body>
</html>
Please tell me what is wrong. Thanks
I found : the issue came from my json files. I defined many "securityDefinitions", one per user role
...,
"securityDefinitions":{
"administrator":{
"type":"basic",
"description":"The administrator."
},
"supervisor":{
"type":"basic",
"description":"A supervisor."
},
"customer":{
"type":"basic",
"description":"A customer."
}
},
...
and for each WS, I indicate which roles are authorized. By example :
...,
"get":{
"security":[
{
"administrator":[
]
},
{
"supervisor":[
]
}
],
...
},
...
By removing security section in WS, all is working.
In swagger editor, we need security section to test WS, but in swagger ui, this section produce an error :-(

IOS database app(phonegap)- working on simulator but not working on device

I build an iphone app using phonegap. I am using sqlite3 db to store the data locally. The app is working perfectly on simulator but gives error on actual ios device. It is throwing "Could not prepare statement (1 no such table: table_name)" error code for the same is Code=5.
Do i have to install sqlite plugin on ios device? The app is in a testing stage. I followed steps provided in this, to install the app on ios device.
What am I missing here?
Update:
This is the piece of code I'am using. My db resides at location
/Users/imac/Library/Application Support/iPhone
Simulator/7.0.3/Applications/4C7CC11A-8938-479F-B810-86121D3311B7/Library/WebKit/Local Storage/File_0
And on the device it resides at
AppData/Library/WebKit/Local Storage/File_0
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<title>Books | Categories</title>
<link href="css/bootstrap.css" rel="stylesheet" type="text/css">
<link href="css/style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" charset="utf-8" src="js/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8">
var db;
var shortName = 'Books';
var version = '1.0';
var displayName = 'BooksDB';
var maxSize = 200000;
function errorHandler(transaction, error) {
alert('Error: ' + error.message + ' code: ' + error.code);
}
function successCallBack() {
alert("DEBUGGING: success");
}
function nullHandler(){
alert('null handler');
};
function onBodyLoad(){
if (!window.openDatabase) {
alert('Databases are not supported in this browser.');
return;
}
db = window.openDatabase(shortName, version, displayName, maxSize);
alert('db open');
ListDBValues();
}
function ListDBValues() {
var ArrayAlphabet=new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
$('.container').empty();
for (var i = 0; i < ArrayAlphabet.length; i++) {
data='<div class="order" id="'+ArrayAlphabet[i]+'"></div>';
load_books(ArrayAlphabet[i]);
$('.container').append(data);
data="";
}
return;
}
function load_books(bookTitleAlphabet)
{
if (!window.openDatabase) {
alert('Databases are not supported in this browser.');
return;
}
db.transaction(function(transaction) {
transaction.executeSql('SELECT * FROM books where book_title like "'+bookTitleAlphabet+'%" order by book_title desc;', [],
function(transaction, result) {if (result != null && result.rows != null) {
$('#'+bookTitleAlphabet).html(bookTitleAlphabet);
for (var i = 0; i < result.rows.length; i++) {
var data;
var row = result.rows.item(i);
data="<a href='details.html?id="+row.book_id+"'> <div class='book'>";
data +="<div class='book_img'><img src="+row.book_thumb_location+"></div>";
data +="<div class='book_detail'>";
data +="<div class='title'>"+row.book_title+"</div>";
data +="<div class='author'>"+row.book_author+"</div>";
data +="</div>";
data +="<div class='clear'>";
data +="</div>";
data +="</div>";
data +="</a>";
var tempId='#'+bookTitleAlphabet;
$(tempId).append(data);
tempId="";
}}
if (result.rows.length==0)
{
var tempId='#'+bookTitleAlphabet;
$(tempId).hide();
}
},errorHandler);},errorHandler,nullHandler);
return;
}
</script>
</head>
<body onload="onBodyLoad()">
<div id="wrapper">
<div class="overflow_hide">
</div>
<div class="menu">
<div class="header">
<div class="back">
<a href="index.html">
<input class="gobutton" type="button" value="Back" ></a>
</div>
<div class="list_book">BOOKS
</div>
<div class="settings">
<a href="index.html">
<input class="gobutton" type="button" value="Home" ></a>
</div>
</div>
<div class="container">
<div class="clear">
</div>
</div>
</div>
<div class="opac">
<a href="about.html">
<div class="opac1">About Us
</div></a>
<a href="search.html">
<div class="opac1">Search
</div></a>
</div>
<div class="clear">
</div>
</div>
</body>
</html>
Is this because the app cannot find the db?
EDITED/NEW ANSWER:
As the article here points out, you will likely have to do some work in XCode itself. As you correctly noted, the pathing to the database is different for pre-populated versus runtime-created databases. In short, your modifications will look for the pre-populated database and move it to the expected location/folder when it is detected. The nice thing: this will happen before your code begins to execute (javascript) so your existing code won't be "aware" that this even happened.
It is worth noting that the post I am referring you to goes past this and excludes the item from backup to iCloud. You will have to make a judgment call on whether you want to do that or not. It is pre-populated does not mean you wish to NOT back up that database nor does it make the leap (as the author does) that the pre-populated database is likely "large".
OLD ANSWER:
The error does not seem to indicate that it is having difficulty with SQLite itself, but a problem with a specific table not existing.
This typically happens when you are testing (via simulator) and at some point hit the appropriate code that performs the CREATE statement for the table. Then, later on, you get accustomed to that table being there and accidentally disconnect the schema-checking or table-existance-checking code. Since the table exists already, your simulator continues on about and never tries to re-create that table. When you go to run it on the actual device, however, that CREATE code never executes and falls into an area where you expect the table to exist - which causes the error.
Since you haven't posted any code, this is all conjecture on my part. If you want me to take a look, I would be happy to.

TideSDK don't chage mainWindow Page

I'm trying to make an app with an login form (index.html) and a mini control panel (panel.html), but when i try to login the app only show the Notificaction and dont redirect to the panel.html page.
This is the code of my index.html
<script type="text/javascript">
function loginTrue() {
Ti.UI.currentWindow.setURL("app://panel.html");
}
function showNotify(title, message) {
var notification = Ti.Notification.createNotification({
'title': title || 'Sin Titulo',
'message': message || 'Sin mensaje',
'timeout': 10
});
notification.show();
}
</script>
<script type="text/javascript">
</script>
<script type="text/python">
import MySQLdb
import os
db = MySQLdb.connect(host="localhost",user="root", passwd="toor", db="db")
cursor = db.cursor()
def login():
username= document.getElementById('usuario').value;
passw= document.getElementById('contrasena').value;
cursor.execute("SELECT * FROM usuarios WHERE userlUsuario='"+username+"' and userContrasena='"+passw+"'" )
res = cursor.fetchone()
if(res==None):
showNotify("Error!", "Datos Invalidos, intente de nuevo.");
else:
showNotify("Acceso!", "Login Correcto!");
loginTrue();
</script>
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="css/style.css" media="all" />
</head>
<body class="login">
<div class="login">
<section id="login">
<h1><strong>Login</strong></h1>
<form method="link">
<input id="usuario" type="text" placeholder="Usuario" />
<input id="contrasena" type="password" placeholder="Contraseña" />
<button class="blue" onclick="login()">Entrar</button>
</form>
</section>
</div>
</body>
</html>
I found it, the problem was with the Login form that redirects the page to it self when someone click on the submit button, i resolve it adding "javascript:void(0);" as action of the form.
<form action="javascript:void(0);">

facebook open graph recipe action not working

I have experienced a problem with facebook open graph (the cook action and recipe object).here is my url
http://www.webcoachbd.com/tester.html
When i click "Cook" it shows an alert "Error occurred [object Object]". I have seen the related topics and tried those,but problem not solved.
This is my tester.html
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"
xmlns:fb="https://www.facebook.com/2008/fbml">
<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# rejoanxxxx: http://ogp.me/ns/fb/rejoanxxxx#">
<meta property="fb:app_id" content="12xxx" />
<meta property="og:type" content="rejoanxxxx:recipe" />
<meta property="og:url" content="http://www.webcoachbd.com/tester.html" />
<meta property="og:title" content="Sample Recipe" />
<meta property="og:image" content="http://www.webcoachbd.com/images/animl136.jpg" />
<script type="text/javascript">
function postCook()
{
FB.api( '/me/rejoanxxxx:cook?recipe:http://www.webcoachbd.com/tester.html',
'post',
function(response) {
if (!response) {
alert('Error occurred : No Response');
} else if (response.error) {
alert('Error occurred : ' + response.error);
} else {
alert('Cook was successful! Action ID: ' + response.id);
}
});
}
</script>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '[123xxxxxxxx]', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
<h3>Stuffed Cookies</h3>
<p>
<img title="Stuffed Cookies"
src="http://www.webcoachbd.com/images/animl136.jpg"
width="550"/>
</p>
<br>
<form>
<input type="button" value="Cook" onclick="postCook()" />
</form>
and application basic setting is
App Domains:webcoachbd.com
Site URL:http://webcoachbd.com
I check my url (http://www.webcoachbd.com/tester.html) with facebook debugger,do not show any error or warning.
Is there are any solution to this problem?Please help.
You have used a colon (:) instead of an equals sign (=) when posting.
Change this: /me/rejoanxxxx:cook?recipe:http...
To this: /me/rejoanxxxx:cook?recipe=http...
When i click "Cook" it shows an alert "Error occurred [object Object]".
The alert method can not display object structures, so you just get [object Object] in that debug attempt.
Use console.log(response.error) instead, and then have a look into your browser’s JavaScript console to see what the actual error is.

jquery unable to bind functions

I am trying to attach onBlur and onFocus handler to a SSN input field. However, I am seeing an error saying object has no method 'ON'. The code is at http://jsfiddle.net/H4Q5f/
As you can see, I commented out to figure out the details, however had no luck so far. Any help is appreciated. For convenience, here is the code:
HTML:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Test Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
<script type="text/javascript" src="../../appjavascript/ssa/mkwr/mytest.js"></script>
</head>
<body>
<div data-role="page" id="MyTestPage">
<div data-role="header" data-position="fixed" data-logo="true" data-tap-toggle="false" data-fullscreen="false" >
<h1> Page Title </h1>
</div>
<div data-role="content">
<div class="content-primary divcontent">
<h1 class='h1title'>Using This App</h1>
<p> Here are the instructions </a>
</p>
</div>
<div class="inputdata">
<br /> <br />
<input type="text" name="accessCode" id="AccessCode" value="" placeholder="Access Code:" /> <br />
<input type="text" id="ssn1" class="ssn" value="" placeholder="SSN1:" /> <br />
<input type="text" id="ssn2" class="ssn" value="" placeholder="SSN2:" /> <br />
</div>
<input type="button" id="myalert" value="Next" />
</div>
<!-- /content -->
</body>
</html>
And here is the java script
if (typeof TEST == "undefined" || !TEST) {
var TEST = {};
}
( function() {
TEST.mkwr = {
init : function() { // this is a public function
$("[data-role='page']").on("pagebeforeshow", TEST.mkwr.hideError());
$("[data-role='page']").on("pageshow", TEST.mkwr.setHandlers());
},
// On Blur, we need to add the '-'s if they doesn't exist so the user
// view edit the entered value formatted
ssnOnBlurHandler : function(input) { // Auto format SSN on blur
if ($(input).val().length == 9) {
var _ssn = $(input).val();
var _ssnSegmentA = _ssn.substring(0, 3);
var _ssnSegmentB = _ssn.substring(3, 5);
var _ssnSegmentC = _ssn.substring(5, 9);
$(input).val(
_ssnSegmentA + "-" + _ssnSegmentB + "-" + _ssnSegmentC);
}
}, // _ssnOnBlurHandler
// On focus, we need to remove the '-'s if they exist so the user
// can edit the entered value
ssnOnFocusHandler : function(input) {
// allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY
if ($(input).val().length == 11) {
var _ssn = $(input).val();
var _ssnSegmentA = _ssn.substring(0, 3);
var _ssnSegmentB = _ssn.substring(4, 6);
var _ssnSegmentC = _ssn.substring(7, 11);
$(input).val(_ssnSegmentA + _ssnSegmentB + _ssnSegmentC);
}
}, // _ssnOnFocusHandler
// Hide all errors
hideError : function() {
$(".error").hide(); // Hide all errors
},
setHandlers : function() {
alert("Set Handlers");
// $(".ssn").each( function() {
// var input = this; input.blur(TEST.mkwr.ssnOnBlurHandler(input))
// });
// $(".ssn").each( function() {
// var input = this; input.focus(TEST.mkwr.ssnOnFocusHandler(input))
// });
}
};
})(); // end the anonymous function
$("[data-role='page']").bind("pageinit", TEST.mkwr.init());
I found a couple of issues with the code on the jsfiddle. Here is an updated one that is working to fire handlers and parse code. It looks like your ssn logic might need to be fixed a little but everything is getting you to there.
http://jsfiddle.net/H4Q5f/10/
The problems I saw were partly what was mentioned before you were using .on instead of .bind given the jquery version. But also you were not setting your handlers but rather firing your handlers. You had this:
input.bind("blur",TEST.mkwr.ssnOnBlurHandler(input))
which would return the result of the function to the set method which is not what you were looking for. So I changed it to this:
input.bind("blur",TEST.mkwr.ssnOnBlurHandler)
So now you are passing the handler to the set method so that it will fire when the event takes place.
Hope this makes sense.
The .on() function was introduced in jQuery 1.7. The code you've posted above includes jQuery 1.6.4 (<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>), which doesn't have that function. You can either upgrade to the latest version of jQuery (recommended) or use the equivalent function - .bind() - for the older versions.

Resources