I am trying user authentication with firebase in java using spring framework. When ever I try to authenticate a user using the provided emailId and password I am getting a 400 Error, but the emailId does exist in the fireBase authentication as well as in the firebase realtime database page. I am also able to retrieve data using uuid which is available in fireBase authentication web page.
My code:
String googleAuthUrl =
env.getProperty("google.auth.identity.toolkit.url") +
env.getProperty("google.auth.identity.toolkit.key");
Client client = Client.create();
WebResource webResource = client.resource(googleAuthUrl);
ClientResponse response = webResource.accept("application/json").type("application/json")
.post(ClientResponse.class, inputJson);
Integer responseCode = response.getStatus();
String responseBody = response.getEntity(String.class);
logger.info("Google response : {}", responseBody);
// ...
My input :
{
"email": "abc#gmail.com",
"password":"test123"
}
Exception encountered:
Google response : {
"error": {
"code": 400,
"message": "EMAIL_NOT_FOUND",
"errors": [
{
"message": "EMAIL_NOT_FOUND",
"domain": "global",
"reason": "invalid"
}
]
}
}
Can anyone explain the reason for this exception and how to overcome the problem ! Instead of making a REST call is there an SDK available for user authentication ?
I just had a similar problem with same library but in flutter.
The problem was that I was sending the email with a white space at the end...
So, I don't know if you solved it but a trim() function can solved it, if is the case sure
Related
I am trying to post a text on LinkedIn using UGC through Postman.
Here is my request body:
{
"author": "urn:li:person:{uid of my account}",
"lifecycleState": "PUBLISHED",
"specificContent": {
"com.linkedin.ugc.ShareContent": {
"shareCommentary": {
"text": "Hello World! This is my first Share on LinkedIn!"
},
"shareMediaCategory": "NONE"
}
},
"visibility": {
"com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
}
}
Note: uid of my account is fetched through - https://api.linkedin.com/v2/me
The response I am getting is:
{
"message": "ERROR :: /author :: \"urn:li:person:oQRNppEnm\" does not match urn:li:company:\\d+|urn:li:member:\\d+\n",
"status": 422
}
Can anyone please help out here?
I had such a mistake. I used wrong value from https://api.linkedin.com/v2/me request answer. You need to add id in your request query if you haven't already,
for example
https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName)
also you need to use value from id field of JSON answer:
{"id\":\"XyyyyXXXXX\"}
It will be some kind of value with numbers and letters, not just numbers.
I am getting an Internal Server Error(500) when creating a paypal payment with Java code using json payload in Sandbox.
I made this with json:
{
"intent": "sale",
"redirect_urls":
{
"return_url": "somelink",
"cancel_url": "somelink"
},
"payer":
{
"payment_method": "paypal"
},
"transactions": [
{
"amount":
{
"total": "17",
"currency": "EUR"
},
"description": "This is payment tran."
}]
}
I tried to complete the same stuff using postman and I can do that. In fact I completed the whole payment transaction(approval and execution) using postman
I am passing proper access token with Bearer.
HttpPost paymentPost = new HttpPost("api.sandbox.paypal.com/v1/payments/payment");
paymentPost.setHeader(HttpHeaders.AUTHORIZATION, pt.getTokenType() + " " + pt.getAccessToken());
List<NameValuePair> nvPairs = new ArrayList<NameValuePair>(4);
nvPairs.add(new BasicNameValuePair("content-type", "application/json")); nvPairs.add(new BasicNameValuePair("Accept", "application/json"));
paymentPost.setEntity(new UrlEncodedFormEntity(nvPairs));
You are setting the content type and Accept to body of the request and not to headers. And also in your code i don't see where you are adding the json to the request. Maybe you are doing that and have not shown it in your code you posted. . You need to use addHeader for adding both the headers. Maybe you can try the below code and see if it fixes the issue.
HttpPost paymentPost = new HttpPost("api.sandbox.paypal.com/v1/payments/payment");
paymentPost.setHeader(HttpHeaders.AUTHORIZATION, pt.getTokenType() + " " + pt.getAccessToken());
paymentPost.addHeader("content-type", "application/json");
paymentPost.addHeader("Accept", "application/json");
paymentPost.setEntity(new StringEntity(/**"YOUR JSON STRING"**/));
Below is the JSON data which contains rich text/wiki text. I want to pass this data to to one of the issues in Jira through REST API. Here Java is the technology, I am using.
{"update":{"summary": [{"set": "CRF-397 – For Virgin Mobile, alert must be sent via email when Tier Mismatch exception is encountered."}]},"fields":{"description":{"set":"*Clients Impacted** Virgin Mobile *Background Information*<br>All UK schemes are experiencing at different levels some issues of:* Customers being billed on the wrong premium* Excess Fees paid at point of claim do not correspond to what has been communicated to the customer at the point of sale.* Welcome packs not being issued due to a mismatch *CRF Scope*<br>The scope of this project consists of identifying whenever a new device is communicated to Asurion by a client system and ensuring the data in each of those instances is validated to confirm that the device premium and excess fees are correctly aligned.*User Story Scope*<br>While doing enrollment if any record goes into exception due to Tier is match we have to send consolidated list of such records via email so that Asurion Team can communicate with Virgin Mobile to resolve the Tier Mismatch issues.*Requirement** An email alert must be sent when Tier Mismatch exception is encountered.* Flag based development must be done for triggering an email.* Email must be sent to Client Service, SCM and BI teams* Recipient email IDs must be configurable.* Exception list must contain below records:- * The list of devices for which there was an exception * The Feature Code sent by Virgin Mobile * The feature code configured in Client Convention for the given device*"}}}
Above JSON I am storing in jiraUpdateFromBuilder.
I am calling PUT method to update description in Jira, as below.
String _jiraUrl = applicationProperties.get(Constants.JIRAURL)
+ "/rest/api/2/issue/" + reference;
String _jiraUser = applicationProperties.get(Constants.JIRAUSER);
String _jiraPwd = applicationProperties.get(Constants.JIRAPWD);
String auth = new String(Base64.encode(_jiraUser + ":" + _jiraPwd));
int statusCode = invokePutMethod(auth, _jiraUrl.trim(),
jiraUpdateFromBuilder.toString().trim());
public static int invokePutMethod(String auth, String url, String data) {
int statusCode = 0;
try {
Client client = Client.create();
WebResource webResource = client.resource(url);
ClientResponse response = webResource
.header("Authorization", "Basic " + auth)
.type("application/json").accept("application/json")
.put(ClientResponse.class, data);
statusCode = response.getStatus();
return statusCode;
} catch (Exception e) {
Constants.ERROR.info(Level.INFO, e);
}
return statusCode;
}
Doing so, I am unable to update description of issue in Jira, through any REST API, because here getting status other than 201. And the same problem is with all the field of an Issue in JIRA which contains rich text. Kindly let me know if JRJC can help else if I need to change in JSON or any other approach.
Your json looks like this:
{
"update": {
"summary": [
{
"set": "CRF-397 ..."
}
]
},
"fields": {
"description": {
"set": "..."
}
}
}
But the "fields" part does not require to use the 'set' keyword, so it should be something like this:
{
"update": {
"summary": [
{
"set": "CRF-397 ..."
}
]
},
"fields": {
"description": "..."
}
}
If you check the documentation for the PUT /issue REST resource, you'll see that it mentions this:
Specifying a "field_id": field_value in the "fields" is a shorthand for a "set" operation in the "update" section.
Field should appear either in "fields" or "update", not in both.
Also, you've mentioned that your response status code was 400, which means it's a bad request. The response body will probably contain more detail about what is wrong, so it's best to log that as well.
Regarding this error:
Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n at [Source: org.apache.catalina.connector.CoyoteInputStream#20e841d2; line: 1, column: 187]
Your description value contains newlines, but it's not allowed to use those in a json string directly. You'll have to escape those. See this post for an example.
The Jira documentations and these answers seem to be outdated. With API version 3 of Jira. (API docs to edit issue)
Updating the description of an Issue in Jira:
HTTP Method: PUT
HTTP URL: https://cognitedata.atlassian.net/rest/api/3/issue/{issueIdOrKey}
Request Body:
{
"fields": {
"description": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "add your description here"
}
]
}
]
}
}
}
If you use a different request body, you will get the following error:
{
"errorMessages": [],
"errors": {
"description": "Operation value must be an Atlassian Document (see the Atlassian Document Format)"
}
}
I faced following problem:
I wanna get list of changes from gerrit repository using this api function https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes
When I sent GET request in browser I got response
[
{
"id": "business~develop~I65d58a2345346cb35a0ecbb63d6ed896c7",
"project": "business",
"branch": "develop",
"hashtags": [],
"change_id": "I65d58a2a045645636cb35a0ecbb63d6ed896c7",
"subject": "Leader property deleted from organizational unit classes. Org unit\u0027s employees cascad type removed. Employee\u0027s roles amount limited by 1 in orgUnit.xsd. Employees identifiers changed in orgUnit.xml. Updated domain model. DataUploadRestService created. Emp",
"status": "NEW",
"created": "2015-05-12 14:31:48.226000000",
"updated": "2015-07-07 07:34:35.195000000",
"mergeable": true,
"insertions": 3100,
"deletions": 1358,
"_number": 589,
"owner": {
"_account_id": 1003473
}
}
]
But when I send GET request using RestEasy or other way to send request using Java code:
try {
final ResteasyClient client = new ResteasyClientBuilder().build();
final ResteasyWebTarget target = client
.target("https://gml-jbpm.gomel.iba.by/gerrit/changes/");
String response = target.request().get(String.class);
final JSONArray array = new JSONArray(response);
System.out.println("RestEasy response: " + array);
} catch (final Exception e) {
e.printStackTrace();
}
I get empty response:
[]
How to solve this problem? Why I get empty JSONArray?
I'm doing sign in with Google+ and always I received the token correctly but when I want to make a request with this token to "https://www.googleapis.com/plus/v1/people/me" via curl. I always get the same error.
Code android to make login:
// Scope to get the token with the user information
public static final String SCOPE_GOOGLE_USER_INFORMATION = "https://www.googleapis.com/auth/userinfo.profile";
public static final String SCOPE_GOOGLE_PLUS_ME = "https://www.googleapis.com/auth/plus.me";
public static final String SCOPE_GOOGLE_PLUS_LOGIN = "https://www.googleapis.com/auth/plus.login";
public static final String SCOPE_GOOGLE_PLUS_EMAIL = "https://www.googleapis.com/auth/userinfo.email";
public static final String SCOPE = "oauth2:" + SCOPE_GOOGLE_USER_INFORMATION + " " + SCOPE_GOOGLE_PLUS_ME + " " + SCOPE_GOOGLE_PLUS_LOGIN + " " + SCOPE_GOOGLE_PLUS_EMAIL;
String token = GoogleAuthUtil.getToken(activity, userEmail, SCOPE);
And then I make the curl request:
curl -H "Authorization: Bearer TOKEN" https://www.googleapis.com/plus/v1/people/me?key={KEY}
Always I received the same error:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
but If I do the same process via https://developers.google.com/oauthplayground/ works
You key and access token have to be from the same project. You can check the project number of the access token by plugging it into to: https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=
Remove the plus.me scope as well, that is not needed. The email and profile scopes can be replaced with the strings "email" and "profile" respectively (no https://wwww.googleapis.com etc.). plus.login is reasonable, but if you're just getting basic profile, you don't need it - the profile scope will give you that from the plus API.