Google Apps Email Settings API allows you to create new aliases (Send mail as) but I can't find a way to update the signature for the alias accounts only the signature for the account it self.
On the Gmail Settings >> General Tab : Signatures , you can define the signature for each alias ... I need to update all that signatures. Is there a way to retrieve and update ALIAS signatures via Email Settings API ?
What is the corresponding API for Email Settings in the new Google APIs Client Library for Java or is it wrong to say it is new and it is replacing gdata-java-client API
Note: Yes, I'm talking about Google Apps domain users
There is no way (to my knowledge) to update the signature of aliases programmatically because there is no exposed API. You can only do it through the UI.
The Email Settings API is still based on the old Gdata Atom based API infrastructure. Google are pretty good with their communications about this and would update the Email Setting API main page.
Aliases are also used to manage signatures for an account.
Sounds like Account == Alias for signatures?
You may also configure email signatures for each alias. For example, to set the signature for the user's primary address:
SendAs primaryAlias = null;
ListSendAsResponse aliases = gmailService.users().settings().sendAs().list("me").execute();
for (SendAs alias: aliases.getSendAs()) {
if (alias.getIsPrimary()) {
primaryAlias = alias;
break;
}
}
SendAs aliasSettings = new SendAs().setSignature("I heart cats.");
SendAs result = gmailService.users().settings().sendAs().patch(
"me",
primaryAlias.getSendAsEmail(),
aliasSettings)
.execute();
System.out.println("Updated signature for " + result.getDisplayName());
https://developers.google.com/gmail/api/guides/alias_and_signature_settings#managing_signatures
Related
In Payment Intent API (https://stripe.com/docs/api/payment_intents/object) ,
Many of the places it is written "RETRIEVABLE WITH PUBLISHABLE KEY" fo ex- id, currency, payment_method, what does it mean?
Whether it means that we can retrieve these value when we integrating the client SDK?
The publishable key is used in your client-side code
https://stripe.com/docs/keys#:~:text=On%20the%20client%2Dside.%20Can%20be%20publicly%2Daccessible%20in%20your%20web%20or%20mobile%20app%E2%80%99s%20client%2Dside%20code
So yes, when using Stripe SDK on your client-side using the publishable key (pk_xxx) you can retrieve only the fields that mention “retrievable with publishable key” in the doc.
If you use your secret key (sk_xxx) to retrieve a PaymentIntent, you will get access to all its properties.
Also, if you want to create a PaymentIntent you must use the secret key in your backend.
I'm using the web3j library with the generated SmartContract wrapper. I'm able to successfully sign a transaction, deploy it to 3rd party node, and interact with the smart contract using the keystore file and the password
Credentials credentials = WalletUtils.loadBip39Credentials(
"testpassword1",
"/path/to/key/store"
);
FastRawTransactionManager txMananger = new FastRawTransactionManager(web3, credentials, Constants.CHAIN_ID);
Optional<TransactionReceipt> receipt = SmartContract.deploy(
web3,
txMananger,
new CustomerGasProvider(),
"param1",
"param2",
"param3"
).send().getTransactionReceipt();
I'm now trying to use the mnemonic to sign the transaction and deploy it. But I can't get it to work because I believe I'm using the Credentials with the WalletUtils for the mnemonic incorrectly.
Credentials credentials = WalletUtils.loadBip39Credentials(
"password25", //Password
"art cat devote sauce lamb derive lawn awesome pole zebra original dog" //Mnemonic
);
https://docs.web3j.io/4.8.7/transactions/credentials/
What am I doing incorrectly here when creating the credentials using the mnemonic?
Credentials.create("0x2a52055c3...") using private key loads the correct address, using the .keystore and password also loads the correct address. Can't figure out why using the mnemonic method is not loading the correct address.
I found some issues on the web3j issues page from a few years ago:
https://github.com/web3j/web3j/issues/639
I want to verify an Android IAP via Google's API on my central game server.
There is a lot of partial information about this and it is blowing my mind.
I have not paid €25 to become a Google Developer, because I am not sure if I will be able to get it to work.
When an IAP is made, a JSON object is returned. This object contains several fields, like the purchaseToken and the productId (source).
I found that you can request information about a bought product via the following GET request: GET https://www.googleapis.com/androidpublisher/v2/applications/packageName/purchases/products/productId/tokens/token.
I could program this no problem, but you need to authorize yourself: "This request requires authorization with the following scope" (source).
This is where I started getting confused.
You need to create some sort of login token via the Dev Console (Link). I don't know what type. OAuth or service account?
This token is short lived. You need to refresh it
There are several huge code snippets to be found on the internet that may or may not work, but they are all partial and not very well documented.
I found Googles API library for Java: link. This API seems to be made to fix all these problems with OAuth and tokens for you. However, I am unable to figure out how to get this API to work.
It is probably not that hard, but there are a lot of different ways to do it, and I can't find any clear examples.
TL;DR: I need to verify a Google Play IAP serverside. To do this, I want to use Googles Java API.
EDIT: THIS MIGHT BE A WAY SIMPLER SOLUTION.
Passing the original JSON plus the JSON to the server might be way easier, because I could just verify the asymmetric signature server side.
I have done that in Scala, but using the Java standard Library. it should be simple to convert that code to Java I believe. The main advantage of this implementation is that it contains zero dependencies on Google's libraries.
First of all, you need a service account. You can create that via the Google Dev console. It basically gives you back a generated email account that you will use to authenticate your backend service and generate the tokens.
With that account created, you are prompt to download your private key. You need that in order to sign the JWT.
You have to generate a JWT in the format Google specifies (I show you how in the code below).
See: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatingjwt
then, with the JWT, you can request the access token
With the access token, you can make requests to validate your purchases
/** Generate JWT(JSON Web Token) to request access token
* How to generate JWT: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatingjwt
*
* If we need to generate a new Service Account in the Google Developer Console,
* we are going to receive a .p12 file as the private key. We need to convert it to .der.
* That way the standard Java library can handle that.
*
* Covert the .p12 file to .pem with the following command:
* openssl pkcs12 -in <FILENAME>.p12 -out <FILENAME>.pem -nodes
*
* Convert the .pem file to .der with the following command:
* openssl pkcs8 -topk8 -inform PEM -outform DER -in <FILENAME>.pem -out <FILENAME>.der -nocrypt
*
* */
private def generateJWT(): String = {
// Generating the Header
val header = Json.obj("alg" -> "RS256", "typ" -> "JWT").toString()
// Generating the Claim Set
val currentDate = DateTime.now(DateTimeZone.UTC)
val claimSet =Json.obj(
"iss" -> "<YOUR_SERVICE_ACCOUNT_EMAIL>",
"scope" -> "https://www.googleapis.com/auth/androidpublisher",
"aud" -> "https://www.googleapis.com/oauth2/v4/token",
"exp" -> currentDate.plusMinutes(5).getMillis / 1000,
"iat" -> currentDate.getMillis / 1000
).toString()
// Base64URL encoded body
val encodedHeader = Base64.getEncoder.encodeToString(header.getBytes(StandardCharsets.UTF_8))
val encodedClaimSet = Base64.getEncoder.encodeToString(claimSet.getBytes(StandardCharsets.UTF_8))
// use header and claim set as input for signature in the following format:
// {Base64url encoded JSON header}.{Base64url encoded JSON claim set}
val jwtSignatureInput = s"$encodedHeader.$encodedClaimSet"
// use the private key generated by Google Developer console to sign the content.
// Maybe cache this content to avoid unnecessary round-trips to the disk.
val keyFile = Paths.get("<path_to_google_play_store_api.der>");
val keyBytes = Files.readAllBytes(keyFile);
val keyFactory = KeyFactory.getInstance("RSA")
val keySpec = new PKCS8EncodedKeySpec(keyBytes)
val privateKey = keyFactory.generatePrivate(keySpec)
// Sign payload using the private key
val sign = Signature.getInstance("SHA256withRSA")
sign.initSign(privateKey)
sign.update(jwtSignatureInput.getBytes(StandardCharsets.UTF_8))
val signatureByteArray = sign.sign()
val signature = Base64.getEncoder.encodeToString(signatureByteArray)
// Generate the JWT in the following format:
// {Base64url encoded JSON header}.{Base64url encoded JSON claim set}.{Base64url encoded signature}
s"$encodedHeader.$encodedClaimSet.$signature"
}
Now that you have the JWT generated, you can ask for the access token like that:
/** Request the Google Play access token */
private def getAccessToken(): Future[String] = {
ws.url("https://www.googleapis.com/oauth2/v4/token")
.withHeaders("Content-Type" -> "application/x-www-form-urlencoded")
.post(
Map(
"grant_type" -> Seq("urn:ietf:params:oauth:grant-type:jwt-bearer"),
"assertion" -> Seq(generateJWT()))
).map {
response =>
try {
(response.json \ "access_token").as[String]
} catch {
case ex: Exception => throw new IllegalArgumentException("GooglePlayAPI - Invalid response: ", ex)
}
}
}
With the access token on your hands, you are free to validate your purchases.
I Hope that helps.
Following on from my comment above, the Google API manager has changed in design but the procedure is still the same. You want to create a Service Account, once created you can download the JSON Web token, it's a simple JSON file with the credentials you need to authenticate. The service account should have all access you need to access the Google Play Developer API. You will need to grant access to Finance in the Google Play Developer Console > Settings > API Access page.
You can use the Google APIs Client Library for Java to authenticate and make requests to the Google Play Developer API. Follow the OAuth2 Service accounts docs to get you set up. There is a note on Data store that describes how the refresh token is handled.
There are also docs on how to use the Google Play Developer API Client Library for Java.
As for validating the signature of the purchase JSON, there is a INAPP_DATA_SIGNATURE in the response payload of the purchase intent. See the docs on Purchasing an Item for more information on how to get it. You can verify the INAPP_PURCHASE_DATA by base64 decoding the signature and verifying it with your licence key, found in the Google Play Developer Console > All Applications > [App name] > Services & APIs. Ensure the INAPP_PURCHASE_DATA is intact otherwise you will end up with this problem.
Hope this helps.
I am trying to authenticate a java app to AWS services using a developer-authenticated Cognito identity. This is very straightforward in the AWS mobile SDKs (documentation), but I can't seem to find the equivalent classes in the Java SDK.
The main issue I am having is that the Java SDK classes (such as WebIdentityFederationSessionCredentialsProvider) require the client code to know the arn of the role being assumed. With the mobile SDK, it uses the role configured for the federated identity. That's what I'd prefer to do, but it seems the Java SDK doesn't have the supporting classes for that.
The last comment from Jeff led me to the answer. Thanks Jeff!
String cognitoIdentityId = "your user's identity id";
String openIdToken = "open id token for the user created on backend";
Map<String,String> logins = new HashMap<>();
logins.put("cognito-identity.amazonaws.com", openIdToken);
GetCredentialsForIdentityRequest getCredentialsRequest =
new GetCredentialsForIdentityRequest()
.withIdentityId(cognitoIdentityId)
.withLogins(logins);
AmazonCognitoIdentityClient cognitoIdentityClient = new AmazonCognitoIdentityClient();
GetCredentialsForIdentityResult getCredentialsResult = cognitoIdentityClient.getCredentialsForIdentity(getCredentialsRequest);
Credentials credentials = getCredentialsResult.getCredentials();
AWSSessionCredentials sessionCredentials = new BasicSessionCredentials(
credentials.getAccessKeyId(),
credentials.getSecretKey(),
credentials.getSessionToken()
);
AmazonS3Client s3Client = new AmazonS3Client(sessionCredentials);
...
If that's the route you want to go, you can find this role in the IAM console, named Cognito_(Auth|Unauth)_DefaultRole. These are what Cognito generated and linked to your pool, and you can get the ARN from there.
This blog post may be of some assistance. All of the APIs the SDK uses to communicate with Cognito to get credentials are exposed in the Java SDK, you just need to use your own back end to get the token itself. Once you have it, you can set the logins the same way you normally would with another provider and it'll all work.
I am using Magento with a 3rd party Java Web Application.
My application is "connected" to Magento via Magento SOAP API V2.
How can I perform a Customer Authentication from my Java aplication (outside of Magento) via api?
Any help would be appreciated.
I came up to a solution on how to login a customer via SOAP API and I will post it here so it can be helpful for others.Here is what I did to make it work:
I created a custom module in Magento with a custom method that login a customer and retuns the sessionID that is set on server side.
Mage::app()->setCurrentStore($website);
// Init a Magento session. This is super ultra important
Mage::getSingleton('core/session');
// $customer Mage_Customer_Model_Customer
// We get an instance of the customer model for the actual website
$customer = Mage::getModel('customer/customer')
->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
// Load the client with the appropriate email
$customer->loadByEmail($email);
// Get a customer session
$session = Mage::getSingleton('customer/session');
$session->loginById($customer->getId());
if ($session->isLoggedIn()) {
return $session->getSessionId();
} else {
return null;
}
I created a Magento Custom Api so I can call my login method via SOAP.
Call the login method from my JAVA app, get the sessionId, then set the cookies on the browser, based on received sessionId.
http://yourmagentohost/setCookies.php?sessionId=your_session_id
And inside setCookies.php you have: setcookie("frontend", $_GET["sessionId"] , time()+3600);
That's it, now you have a logged in customer.
How can I perform a Customer Authentication from my Java aplication
(outside of Magento) via api? SOAP API V2
Clarification:
API Users (at least Soap) and Customer's are two user types. If you have a pre-existing userlist, and are looking to find out if they exist as user's inside of Magento, you may retrieve email account's and their related attributes and corresponding password hash's (CE: md5:salt , or CE/EE: sha:salt) all via SOAP. If you are looking to do comparative operations, you will need to implement the same Hashing against your password's to do 1:1 comparisons. If you are looking to have your Application use SOAP to directly perform operations, I would make sure that there is a layer of abstraction, as your app could be used nefariously targeting other user id's all depending on the SOAP Role and ACL set in Magento's Admin.
Moving on...
V2: You'll have to swap to Java, ex: PHP.
$username 'yourUsername';
$password = 'yourApiKeyPlainText';
$proxy = new SoapClient('https://www.yourdomain.com/magento/api/v2_soap?wsdl=1');
$sessionId = $proxy->login($username, $password);
//Get a Full customer List from Magento
$customerList = $proxy->customerCustomerList($sessionId);
//get back a list
//Target a user from your List, Compare Details against your App
$customerInfo = $proxy->customerCustomerInfo($sessionId, '2'); //Customer Id
Remote operations, like Checkout, can be rather involved. The question remains, what do you wish to do next to, or on behalf of the user with your app?
References:
http://www.magentocommerce.com/api/soap/customer/customer.list.html
http://www.magentocommerce.com/api/soap/customer/customer.info.html
Cheers,
Your code example does not use SOAP. Magento SOAP accesses actually look like the following:
$client = new SoapClient('http://magentohost/soap/api/?wsdl');
// If somestuff requires api authentification,
// then get a session token
$session = $client->login('apiUser', 'apiKey');
Have a look at the API documentation: http://www.magentocommerce.com/api/soap/introduction.html