Hi, I realise now I can’t seem to login using Twitter (X) at all. When I login, instead of redirecting back to the application, it redirects to another X login page. When I login again, it goes to the X interface rather than going back to my application. Anyone can help?
Hi @customautosys,
Could you please clarify if you are using a production key for your Twitter social connection?
And could you check your logs and verify whether you were able to log in?
Let me know about your findings.
Thanks,
Rueben
Dear Rueben,
I was always using a production key, and it was always working in the past. I think X changed something again. Basically instead of going to the redirect it then sends me to another login page of the X login interface and after I login again it goes straight to the X interface and never goes back to my app.
I took a video but unfortunately the system does not allow me to upload it here.
I’m probably not the only one suffering from this problem, it should be affecting all Twitter sign in users.
Hi @customautosys,
Thanks for the reply and clarification.
I have looked for related topics regarding this issue and could not find an identical problem.
Are you able to review your tenant logs? What did you find when checking your logs? Did you see any success login (s
) events?
Thanks,
Rueben
Hi Rueben,
Today I have tested it again and somehow I am able to login now using X.
However, I am facing a problem retrieving the user’s email from X using actions. The equivalent used to work under rules.
Is there any way to debug or view the console logs from running actions? In the past, for rules, we were able to debug it or view the realtime webtask logs.
Hi Rueben, I have made a breakthrough!
I would like to donate my code here:
/**
* Handler that will be called during the execution of a PostLogin flow.
*
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
*/
exports.onExecutePostLogin = async (event, api) => {
if(event.connection.strategy!=='twitter')return;
// additional request below is specific to Twitter
let oauth=require('oauth-sign');
let request=require('request');
let uuid=require('uuid');
let _=require('lodash');
let url='https://api.x.com/1.1/account/verify_credentials.json';
let consumerKey='<your consumer key here>';
let consumerSecretKey='<your consumer secret key here>';
const ManagementClient = require('auth0').ManagementClient;
const management = new ManagementClient({
domain:'<your domain>',
clientId:'<your clientId>',
clientSecret:'<your clientSecret>'
});
let twitterIdentity=null;
try {
let user = await management.users.get({ id: event.user.user_id });
twitterIdentity = _.find(user.data.identities,(/** @type {{ connection: string; }} */ identity) => identity.connection === 'twitter');
} catch (error) {
console.error('Error fetching Twitter email: '+JSON.stringify(error));
return;
}
let oauthToken=twitterIdentity.access_token;
let oauthTokenSecret=twitterIdentity.access_token_secret;
let timestamp=Date.now()/1000;
let nonce=uuid.v4().replace(/-/g,'');
let params={
include_email:true,
oauth_consumer_key:consumerKey,
oauth_nonce:nonce,
oauth_signature_method:'HMAC-SHA1',
oauth_timestamp:timestamp,
oauth_token:oauthToken,
oauth_version:'1.0'
};
params.oauth_signature=oauth.hmacsign('GET',url,params,consumerSecretKey,oauthTokenSecret);
let auth=Object.keys(params).sort().map(function(k){
return k+'="'+oauth.rfc3986(params[k])+'"';
}).join(', ');
try{
let body=await new Promise((resolve,reject)=>request({
url:url+'?include_email=true',
headers:{
'Authorization':'OAuth '+auth
}
},(/** @type {any} */ err,/** @type {{ statusCode: number; }} */ resp,/** @type {string} */ body)=>err||resp.statusCode!==200?reject(new Error('Error retrieving email from twitter: '+body||err)):resolve(body)));
api.idToken.setCustomClaim('email',JSON.parse(body).email);
await management.users.update({id:event.user.user_id},{email});
}catch(/** @type {any} */ error){
return console.error(error);
}
};
/**
* Handler that will be invoked when this action is resuming after an external redirect. If your
* onExecutePostLogin function does not perform a redirect, this function can be safely ignored.
*
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
*/
// exports.onContinuePostLogin = async (event, api) => {
// };
I would still love to know where to find the console log for actions though!
Hi @customautosys,
Thanks for your replies.
Firstly, you can still use the Real-time Webtask Logs Extension to debug your Action scripts during runtime. You should be able to view any errors or logs related to the login event.
And thank you for donating your code to the rest of the community. Yes, one way to get the user’s email is to use the ManagementClient. But you should also be able to get the email address by calling the event.user.email
property.
Please feel free to reach out to us again if you have any questions.
Thanks,
Rueben
Yes, just to clarify, event.user.email does not work by default with X as the X email is not retrieved by auth0 upon login.
I’m not using ManagementClient to retrieve the email but to retrieve the X token. The X token is then used to call the API to retrieve the email which is then used to set a custom claim of email in the ID token. I’m editing my solution above to add another line to use the management API to set the email in auth0 after retrieving it from X.
I’ve been trying to use real-time webtask logs but I always get connection error with no other details.
Hi @customautosys,
Thanks for your reply and clarification.
I recommend reinstalling the extension if you are having issues with using the real-time webtask logs extension.
Thanks,
Rueben
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.