How to handle the auth0 (Authentication Required) popup window in protractor - node.js

Im facing an issue to handle the auth0 pop window. Any leads on how do I handle the same.
NOTE :
1. Protractor is what I'm using.
2. Framework : Jasmine (Nodejs).
Attached is the screenshot for the reference.
Screenshot
Thanks,
Zaid

Finally figured out the solution.
I have a javascript that generates the auth0 token. Once the token is generated I use that token and set that to browser cookies along with user credential. This way when I hit the application url which I want to test, the auth0 browser specific authentication prompt isn't displayed.
Below is the code for the same:
var request = require('request');
this.performAuthoLogin = function() {
var defer = protractor.promise.defer();
var credentials = {
"client_id": clientId,
"username": userName,
"password": password,
"id_token": "",
"connection": connectionName,
"grant_type": "password",
"scope": "openid",
"device": "api"
}
request({
url: url,
method: 'POST',
json: true,
body: credentials,
headers: {
'Content-Type': 'application/json'
}
}, function(error, response, body) {
if (error) {
defer.reject(error);
} else {
authTokenId = body.id_token;
console.log(authTokenId);
var profile = {
username: userNameToLogin
email: emailId
}
browser.manage().addCookie("profile", profile, '/', applicationUrl)
browser.manage().addCookie("id_token", authTokenId, '/', applicationUrl);
defer.fulfill(body);
}
});
return defer.promise;  
};

Related

Request Comment on Behalf not working with zendesk API

I'm making a Node application that uses Zendesk API. Users logged in and can create tickets through my application.
To create tickets, I use this configuration
var config = {
method: 'post',
url: 'url/api/v2/requests.json',
headers: {
'Authorization': 'Bearer adminToken',
'X-On-Behalf-Of': 'emailOfUser',
'Content-Type': 'application/json',
},
data: ticket
};
axios(config)
.then(function (response) {
//My code
})
With X-On-Behalf-Of I can create tickets for the user logged in with my admin token.
However, it doesn't work for updating the ticket with comments. I got a Forbidden error. Here is my code :
var config = {
method: 'put',
url: 'url/api/v2/requests/' + idTicket,
headers: {
'Authorization': 'Bearer adminToken',
'X-On-Behalf-Of': 'emailOfUser',
'Content-Type': 'application/json',
},
data: { "request": { "comment": { "body": message, "public": true, "author_id": userId } } }
};
And when I remove the X-On-Behalf-Of, the comment is publish, but with my name, the admin name, and not the user name.
Do you know a solution for that ?
Thanks
It is likely that your token is missing impersonate scope.
Example for authorization code grant:
https://{subdomain}.zendesk.com/oauth/authorizations/new?client_id=foo&redirect_uri=bar&scope=impersonate+write&response_type=code

How to send current user's(person using the app), Firebase Id token,from the Flutter app, to restapi, using http POST method?

I have created an app using flutter for UI and Restapi in nodejs as the backend. Now i want to verify the user, who signuped with the firebase authentication,the sending the current user's firebase Id token. In order, to do this I am sending the id token using the HTTP Post method. But got an error.
Sample code:
import 'package:http/http.dart' as http;
FirebaseUser user = await FirebaseAuth.instance.currentUser();
if(user!=null){
Future<IdTokenResult> idtoken = user.getIdToken();
}
http.Response response = await http.post("https://www.something.com/something/something",
body:jsonEncode({
"name": name.text,
"pincode": "$pincode",
"token": idtoken,
"phone": "${widget.phoneNo}",
}),
headers: {'Content-Type': 'application/json'},
);
Got Error:
Unhandled Exception: Converting object to an encodable object failed: Instance of 'Future<IdTokenResult>'
P.S: Suggest an edit, if something wrong with the question, I am for ideas (Thanks for the help in advance :) )
You need token(String) not idtoken(IdTokenResult)
import 'package:http/http.dart' as http;
FirebaseUser user = await FirebaseAuth.instance.currentUser();
if(user!=null){
IdTokenResult idtoken = await user.getIdToken();
// get String token
String token = idtoken.token;
}
http.Response response = await http.post("https://www.something.com/something/something",
body:jsonEncode({
"name": name.text,
"pincode": "$pincode",
"token": token,
"phone": "${widget.phoneNo}",
}),
headers: {'Content-Type': 'application/json'},
);
I think the problem is getIdToken() part.
Can you try below code please:
FirebaseAuth.instance.currentUser().then(user => {
if (user != null) {
user.getIdToken().then(token => {
http.Response response = await http.post("https://www.something.com/something/something",
body:jsonEncode({
"name": name.text,
"pincode": "$pincode",
"token": token,
"phone": "${widget.phoneNo}",
}),
headers: {'Content-Type': 'application/json'},
);
}
});

Client must be authenticated to access this resource. jira rest api

I've created a project using node module passport-atlassian-oauth2 and i get the accessToken successfully. But when I do a request to create an issue I get the error
Client must be authenticated to access this resource.
Below is my code for create issue jira api.
Could you help please?
var bodyData = {
"fields": {
"project": {
"key": "FLUX"
},
"summary": "REST ye merry gentlemen.",
"description": "Creating of an issue using project keys and issue type names using the REST API",
"issuetype": {
"name": "Bug"
}
}
};
var baseUrl = 'https://alamrezoanul.atlassian.net';
var options = {
method: 'POST',
url: `${baseUrl}/rest/api/3/issue`,
data: JSON.stringify(bodyData),
headers: { 'Authorization': 'Bearer ' + jiraTokens.accessToken, 'Content-Type': 'application/json' },
json: true };
axios(options)
.then((response2) => {
console.log("response2.data: ", response2.data);
})
.catch((error) => {
console.log("error: ", error);
})
Hi I encountered the same issue today. You need to fetch the cloud id of https://alamrezoanul.atlassian.net and then instead of doing var baseUrl = 'https://alamrezoanul.atlassian.net'; use var baseUrl = 'https://api.atlassian.com/ex/jira/{cloud id}';.
You can fetch the cloud id by doing a authenticated GET request to https://api.atlassian.com/oauth/token/accessible-resources.
You might want to check the audience in your authorised tokens.
https://developer.atlassian.com/cloud/jira/platform/oauth-2-authorization-code-grants-3lo-for-apps/#implementing-oauth-2-0--3lo-
Setup says:
audience: (required) Set this to api.atlassian.com.
You may need to set to alamrezoanul.atlassian.net
Same issue I have fixed instead username and password use email and api token link to generate token
Below code I am using in my project
public String getEncodedAuth() {
String username = "user#gmail.com";//enter your mail
String auth_header = username + ":" + "<API token>";
String encodedAuth = Base64.getEncoder().encodeToString(auth_header.getBytes());
return encodedAuth;
}
public void getIssue(String issueId) {
Response response = RestAssured.given()
.header("Authorization", "Basic " + getEncodedAuth())
.contentType(ContentType.JSON)
.pathParam("issueIdOrKey", issueId)
.queryParam("fields", "attachment")
.when()
.get("https://user.atlassian.net/rest/agile/1.0/issue/{issueIdOrKey}");
response.prettyPrint();
}

fetch not posting form data in zapier

I have a code in zapier:
var username = "username"
var password = "password"
var grant_type = "password"
var client_id = "id"
var ENDPOINT="someUrl"
var json = {
"grant_type": grant_type,
"username": username,
"password": password,
"client_id": client_id
};
var options={
method:"POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
payload:json
}
const result = await fetch(WAVITY_ENDPOINT,options)
const content = await result.json()
output={response:content}
But I am always getting Unauthorized error. I do the same through request module and it works. I think fetch is not sending the data. Any help would be appreciated.In my request module code, I have following options:
headers: {
connection: "Keep-Alive",
timeout: 5000
},
url: ENDPOINT,
method: 'POST',
formData: {
'grant_type': grant_type,
'username': username,
'password': password,
'client_id': client_id
}
NOTE: Changing the headers of fetch to headers like in request also does not work for me.
Per this question about fetch, I believe the key for the data should be body, not payload.
Zapier uses node-fetch (source), so if you can get it working locally with that, you'll be able to paste it into Zapier successfully.

not able to get user info

bellow is my node js script to get google user details using accessToken
var accessToken = req.body.accessToken;
console.log(accessToken)
var google = require('googleapis');
//google api
var plus = google.plus('v1');
var OAuth2 = google.auth.OAuth2;
var oauth2Client = new OAuth2(
config.google.clientID,
config.google.clientSecret,
config.google.redirect_uri
);
oauth2Client.setCredentials({access_token: accessToken});
plus.people.get({
userId: 'me',
auth: oauth2Client
}, function (err, response) {
// handle err and response
if (err) {
reject(err)
} else {
console.log(response);
resolve(response)
}
});
need to get google login user details using accessToken. what is wrong in code?
The most likely cause is the user in question has not created a google+ profile. Here are a few more options.
I am not sure what information you are trying to get but the best way to get user info is to authecate a user using the profile scope then request the data directly of the user info endpoint
Request
GET /userinfo/v2/me HTTP/1.1
Host: www.googleapis.com
Content-length: 0
Authorization: Bearer uzG4XqnvucBFk3jylgxnbtNhoOt2wCc3QvUcjk7PZhJ5m6G7ibtlBwbAQntJjJtLsxZfoDjhbASpzLmcFnlZ9o4qoMd2fCV2eRb4O5XrKRAXC
Response
{
"family_name": "Lawton",
"name": "Linda Lawton",
"picture": "https://lh5.googleusercontent.com/-a1CWlFnA5xE/AAAAAAAAAAI/AAAAAAAAl1I/UcwPajZOuN4/photo.jpg",
"locale": "en",
"gender": "female",
"link": "https://plus.google.com/+LindaLawton",
"given_name": "Linda",
"id": "117200475532672775346"
}
You can also go though the google people api using the same profile scope
GET /v1/people/me HTTP/1.1
Host: people.googleapis.com
Content-length: 0
Authorization: Bearer NuzG4XqnvucBFk3jylgxnbtNhoOt2wCc3QvUcjk7PZhJ5m6G7ibtlBwbAQntJjJtLsxZfoDjhbASpzLmcFnlZ9o4qoMd2fCV2eRb4O5XrKRAXC
But this endpoint reads from Google+ so if the user has not filled anything out on their Google+ profile you wont see much data here.
You can use request module to get the user detail on your node server.
But Before requesting the user data, make sure you have authorized the API by giving it the desired scope. In your case, you need to give https://www.googleapis.com/auth/userinfo.profile in the scope.
When you receive your accessToken, use that token to call this google api
https://www.googleapis.com/oauth2/v1/userinfo
const request = require('request');
// use any api you want to call.
request({
url: 'https://www.googleapis.com/oauth2/v1/userinfo',
method: 'GET',
headers: {
'Authorization': `Bearer ${YourAccessToken}`,
'Accept': 'application/json'
}
}, function(err, response, _user) {
console.log('User Data', _user);
})
I hope this will solve your problem. If still there is some problem, you can test your Google APIs on OAuth 2.0 Playground

Resources