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
Related
Hello I am implementing Box API,
I want to let external user select their existing files and then want to download those files in my application.
For that I have enterprise Application and I am using JWT Authorization.
I am able to generate Access Token using this code
JWTEncryptionPreferences jwtPreferences = new JWTEncryptionPreferences();
jwtPreferences.setPublicKeyID("xxxx");
jwtPreferences.setPrivateKeyPassword("xxx");
jwtPreferences.setPrivateKey("-----BEGIN ENCRYPTED PRIVATE KEY-----\nxxxxxx\n-----END ENCRYPTED PRIVATE KEY-----\n");
jwtPreferences.setEncryptionAlgorithm(EncryptionAlgorithm.RSA_SHA_256);
BoxConfig boxConfig = new BoxConfig("xxxx", "xxxx", "xxx", jwtPreferences);
try {
BoxDeveloperEditionAPIConnection api = BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(boxConfig);
LOG.info("token --" + api.getAccessToken());
return api;
} catch (BoxAPIException e) {
}
Then I am sending this token to the front end and Opening the Content Picker using that token. Code is same as below link
https://developer.box.com/docs/box-content-picker#section-sample-html
Now I am able to open picker just like the demo. But it is specific to one account. I want to implement the same for External Users of Box.
Is this possible?
What I am missing here?
Okay. I found solution for this. Posting this if it can help anyone.
I found that picking JWT for existing app user is not a good choice.
So I have to choose OAuth2 for authenticating external users
From doc:
When to Use Choose OAuth 2 as your authentication method if:
You are only working with users that have existing Box accounts.
My Guidelines
If followed this Google documentation about verifying Google-Account-Tokens on the server side, but I am kinda confused.
My Problem
GoogleIdTokenVerifier googleIdTokenVerifier = new GoogleIdTokenVerifier.Builder(new NetHttpTransport(), new JacksonFactory())
.setAudience(Collections.singletonList(CLIENT_ID))
.build();
In this piece of code I figured out that the transport and jsonFactory arguments can be filled as new NetHttpTransport() and new JacksonFactory() here. It also describes how to get AudienceString, but I couldn't figure out what it is for. I couldn't test it, but my question is if I can use it without .setAudience() or if I need it and what it is for.
In .setAudience() you have to pass all client ID's. You can get the ID for your client from the Credentials Page. It's explained here.
Thanks to #StevenSoneff.
If you didn't get the basic concept
For every client you want your server to accept, you need to create a project in the `Developer Console`. Clients are differentiated by their `SHA-1` fingerprint. You can for example have a debug project (will take your debug fingerprint) and a release one. To make both work, you have to add both `ID`'s to your server's `GoogleIdTokenVerifier`'s `.setAudience()`.
In my case, If you're using Firebase to get the id token on Android or iOS. You should follow these instructions to verify it on your backend server.
Verify ID tokens using a third-party JWT library
For me, I'm using Google OAuth Client as the third-party library so it's easy to use.
But it's a little bit different from this document.
Verify the Google ID token on your server side
The CLIENT_ID is your firebase project ID.
The Issuer has to be set as https://securetoken.google.com/<projectId>.
You need to use GooglePublicKeysManager and call setPublicCertsEncodedUrl to set it as https://www.googleapis.com/robot/v1/metadata/x509/securetoken#system.gserviceaccount.com
GooglePublicKeysManager manager = new GooglePublicKeysManager.Builder(HTTP_TRANSPORT, JSON_FACTORY)
.setPublicCertsEncodedUrl(PUBLIC_KEY_URL)
.build();
GoogleIdTokenVerifier verifier = new GoogleIdTokenVerifier.Builder(manager)
.setAudience(Collections.singletonList(FIREBASE_PROJECT_ID))
.setIssuer(ISSUER)
.build();
If you have multiple issuers, then you have to create GoogleIdTokenVerifier for each one.
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.
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
I have a non-gae, gwt application and it have a module that allows users to create documents online via google docs api.
To do that, i first ask user to enter the name and type of the document, than create a new document via google docs api with the given parameters and onSucces part of that servlet returns edit link which is used in client side to open a new page to edit the created document.
Problem that, eachtime i try to open that editLink user have to enter login informations. To solve this i try to use Google Client Login but i am totally lost i think.
First i have username and password of user and can directly use them, after searching i tried some examples which usually returns a token like this and that. Now what should i do with token? How can it be used to complete login process or should totally find another way to do login? All those oauth1,oauth2 and etc. documentations confused me a little bit.
here are my steps;
Server side;
LinkedHashMap<String, String> hashMap = new LinkedHashMap<String, String>();
// Login
DocumentList docList = new DocumentList("document");
docList.login(ServletUtil.googleDocsLoginInfo().get("username"), ServletUtil.googleDocsLoginInfo().get("password"));
//Create document with a unique suffix
String docName= parameterName+ "-Created-" + new Date();
docList.createNew(docName, dosyaTur);
// Find the created document and store editLink
DocumentListFeed feed = docList.getDocsListFeed("all");
for (final DocumentListEntry entry : feed.getEntries()) {
if (entry.getTitle().getPlainText().equals(docName)) {
hashMap.put("editlink", entry.getDocumentLink().getHref());
}
}
return hashMap;
And Client side;
#Override
public void onSuccess(LinkedHashMap<String, String> result) {
String editLink = result.get("editlink");
Window.open(editLink,"newwindow","locationno");
}
Thanks for your helps.
If I may suggest using OAuth instead of Client Login, which is outdated and less secure.
The functionality is basically the same (for OAuth 2.0 there are more ways to handle the login).
I know, trying to understand how to access the api via OAuth is very confusing, so I try to break it down a little:
If you use OAuth 2.0 you may want to use a library like this one or you can try out my own (although I wrote it for Android, this could work with other Java Apps including Web Apps)
This is what happens when a user logs in the first time with your app:
> Your App sends an authorization request containing some information about your app - for example your app needs to be registered with google and therefore has a special application key
< The Server sends you a url, open it in a new browser window and let the user login. There he will be asked to allow your app to access his account (or some parts of it) - when he confirms he will be prompted an Authorization Code which he needs to copy
> The user gets back to your app, where you will ask him for the authorization code. After he gave it, your app connects again with the server and sends the code as some kind of authorization grant of the user.
< The Server answers with a access token
All you need to do is use this access token (also called a bearer token) in all your requests to the server hidden in the header message.
I am sorry I can't give you a more precise answer right now, since I never used GWT. All I can say is, try using OAuth2, it is actually very simple (after you learn what all this confusing things like authorization flow, bearer token etc are) and really comfortable for your user, once the he has done the first login.