I'm working on custom OAuth2 Authorization Server (old initial version # https://github.com/gvaduha/OAuth2CppLib) that compliant with RFC6749 and would like to use hello.js for one-page clients. What I've done to start with it:
created src/modules/myoauth.js
(function(hello){
hello.init({
myoauth : {
name : 'myoauth',
oauth : {
version : 2,
auth : 'https://localhost/oauth2/authorize',
grant : 'https://localhost/oauth2/token'
},
refresh : false,
scope : {
basic : 'profile'
},
scope_delim : ' ',
base : 'https://localhost/',
get : {
"me" : "profile"
},
}
});
})(hello);
added provider to demos/client_ids.js
var CLIENT_IDS = {
myoauth : 'OAuthTestClientId',
windows : WINDOWS_CLIENT_ID,
google : GOOGLE_CLIENT_ID,
facebook : FACEBOOK_CLIENT_ID
};
added following lines to demos/login-events.html
<button onclick="login('myoauth')">Login myoauth</button>
<script src="../src/modules/myoauth.js"></script>
But all this for nothing. When I click login page following my server authentication then authorization then page reply with 302 redirect to
http://localhost/xxx/redirect.html#token_type=Bearer&access_token=XkGxfTVZWgdFuXTuc64du8DK375JurgOT2CDqv0QGd&expires_in=3600&
and when I closing popup page says
callback:{
"error": {
"code": "cancelled",
"message": "Login has been cancelled"
},
"network": "myoauth"
}auth:{
"error": {
"code": "cancelled",
"message": "Login has been cancelled"
},
"network": "myoauth"
}auth.failed:{
"error": {
"code": "cancelled",
"message": "Login has been cancelled"
},
"network": "myoauth"
}
What have I done wrong? BTW: Google works correct when I've changed it's id to point to my registered application client.
The OAuth2 response does not appear to maintain the 'state' URI parameter in your example given.
Related
I'm newbie on using FCM API for push notifications, but the documentation didn't seem very clear for me. I'm trying to find out what values are accepted by the notification data content. So far, I'm trying to use it on this way:
const data: NotificationData = {
notification : {
title: "Test Notification",
body: "Test Notification Body",
icon: "http://localhost:3001/gmp-icon.png"
},
to: window.FCMToken,
}
I'm posting it against the API url https://fcm.googleapis.com/fcm/send, and I wanted to format it as a web notification, but posteriorly as Android and iOS to be used from react-native.
Where should I add the icon value?
Try to add an object in the body as "data" and this object will have the custom fields you want to send. And send the icon property in the data object. For ex:
{
"to" : "Token",
"notification" : {
"title": "Title of the notification",
"body": "Body of the notification",
"data": {
"click_action": "https://google.com",
"customData": "valueOfCutomData",
"image": "Some valid url",
"icon": "Url of the icon",
"url": "https://google.com"
}
}
}
download png file and place file in android/app/src/main/res/drawable as notification_icon.png
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/ic_notification" />
I Try to create new converation and send proactive message with teams bot (botfreamwork).
I used this document to do that.
I POST to : SERVICE_URL/v3/conversations/
BODY:
{
"bot": {
"id": BOT_ID
},
"members": [
{
"id": USER_ID
}
],
"channelData": {
"tenant": {
"id": TENANT_ID
}
}
}
BOT_ID - I put the app id of the bot (with a prefix of "28:")
USERֹ_ID - I copied the USER_ID from a message I received from the user (not in a proactive message)
TENANT_ID - I took the tenant id from the link of the teams
I get this error:
{
"error": {
"code": "BadSyntax",
"message": "Invalid user identity in provided tenant"
}
}
I made several attempts to change the user ID: I changed to a user that appears in ADD, I changed with a prefix of 29: and without a prefix of 29: - nothing helped, this error continues to appear.
What am I missing?
I'm trying to perform a share with the beginShareFlow()function of the facebook MessengerExtensions. However, when performing the call, I get following error message:
Messenger Extensions unexpected error.
The code for this error is 2018154.
I'm using following code to start a share:
ajax.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
var message = JSON.parse(this.responseText);
MessengerExtensions.beginShareFlow(function(share_response) {
if(share_response.is_sent){
// close the window w/ requestCloseBrowser().
}
},
function(errorCode, errorMessage) {
console.log(errorCode+"-"+errorMessage);
},
message,
"current_thread");
}
}
You'll see that I'm using the response of an ajax call to fill up the actual message. This is generated by some backend php code, an example:
{"attachment":{"type":"template","payload":{"template_type":"generic","sharable":"true","elements":[{"title":"Kerk Poederlee","image_url":"https:\/\/www.wouterh.be\/pogo\/static\/images\/raid.jpg","subtitle":"joining at 1535629500","default_action":{"type":"web_url","url":"https:\/\/www.wouterh.be\/pogo"},"buttons":[{"type":"web_url","url":"https:\/\/www.wouterh.be\/pogo","title":"join raid"}]}]}}}
Messenger extension themselves have been loaded correctly, since I'm able to retrieve the PSID with following code:
window.extAsyncInit = function() {
MessengerExtensions.getContext('APPID',
function success(thread_context){
fb_user_id = thread_context.psid;
},
function error(err){}
);
};
This error occurs on a web client and on the most recent iOS messenger. When I send the exact same message through the Send API instead of the sharing messenger extensions, it works perfectly. Could somebody help me figure out what's causing the error?
I found the mistake, in the message you can pass a 'sharable' property. I passed the string value "true" to it, but this should be a boolean value.
This is the corrected content:
{
"attachment": {
"type": "template",
"payload": {
"template_type": "generic",
"sharable": true,
"elements": [{
"title": "Kerk Poederlee",
"image_url": "https:\/\/www.wouterh.be\/pogo\/static\/images\/raid.jpg",
"subtitle": "joining at 1535629500",
"default_action": {
"type": "web_url",
"url": "https:\/\/www.wouterh.be\/pogo"
},
"buttons": [{
"type": "web_url",
"url": "https:\/\/www.wouterh.be\/pogo",
"title": "join raid"
}]
}]
}
}
}
I'm getting this below exception while running the script after redeployment.Earlier it was working fine but when I added some new functions and redeployed it as API executable., started getting this error.
[17-07-08 20:48:45:404 PDT] {
"error": {
"code": 401,
"message": "ScriptError",
"status": "UNAUTHENTICATED",
"details": [
{
"#type": "type.googleapis.com/google.apps.script.v1.ExecutionError",
"errorMessage": "Authorization is required to perform that action.",
"errorType": "ScriptError"
}
]
}
}
Your OAuth scopes have probably changed. Your client needs to add these new scopes and request a new token with them.
I am trying to access some google APIs from my javascript client using Oauth2. I've succeeded in getting the user to authenticate requests, but there's some unexpected behaviour when running the code below that'd I'd like to understand. When I click the 'authorize' button the first time, the result is:
'[ { "error": { "code": 401, "message": "Login Required", "data": [ { "domain": "global", "reason": "required", "message": "Login Required", "locationType": "header", "location": "Authorization" } ] }, "id": "gapiRpc" } ] '
on the second click the result is
[ { "id": "gapiRpc", "result": { "id": "1115793426680xxxx", "email": "xxxxx#gmail.com", "verified_email": true } } ]
here is the code for the page I am testing
<div id='sign in'>
<button onclick="init();">Authorize</button>
</div>
<p id="output">hello</p>
<script type="text/javascript">
function init() {
document.getElementById('output').innerHTML='loading oauth2 api'
gapi.client.load('oauth2', 'v2', auth);
}
function auth() {
var config = {
client_id: '2264xxxxx-odt0g7jn8vspa3ot9ogjxxxxxxxxx.apps.googleusercontent.com',
scope: 'https://www.googleapis.com/auth/userinfo.email',
immediate:true
};
document.getElementById('output').innerHTML='authorizing'
gapi.auth.authorize(config, authed());
}
function authed() {
document.getElementById('output').innerHTML='authorized'
var request = gapi.client.oauth2.userinfo.get().execute(
function(resp, raw) {
document.getElementById('output').innerHTML=raw
}
);
}
</script>
<script src="https://apis.google.com/js/client.js"></script>
<!--<script src="https://apis.google.com/js/client.js?onload=init"></script>-->
Could you please explain why I would get a 'login required' on the first execution of the code and a successful authentication on the second execution?
Due to the parentheses immediately after "authed" in the call to gapi.auth.authorize, the authed() callback is run immediately, prior to the call to gapi.auth.authorize.
Also, in your authed() handler you need to check to see whether the authorization check with immediate: true succeeded; for more details, see the reference documentation here:
https://developers.google.com/api-client-library/javascript/reference/referencedocs#gapiauthauthorize
Also refer to the section on pop-up blocking here:
https://developers.google.com/api-client-library/javascript/features/authentication#popup
When the "immediate" authorization fails, the authed callback will be invoked with a null token object, or a token object containing an "error" field; in these cases you need to present a user interface element the user can click which will re-run the gapi.auth.authorize call but with "immediate" set to false (or omitted). This allows the authorization pop-up to be opened without running afoul of your browser's pop-up blocker.