I use this to connect to the infura rospten from a react-native mobile app:
const url = 'https://ropsten.infura.io/v3/xxx';
this.web3 = new Web3(new Web3.providers.HttpProvider(url))
when I call a contract, I get:
Error: Invalid JSON RPC response: ""]
why is the error empty?
Using the same method connect to the local ganache, and it works.
Is it because of the authorization or the network configuration?
You need to remove the /v3 part from your URL
Convert
const url = 'https://ropsten.infura.io/v3/xxx';
To:
const url = 'https://ropsten.infura.io/xxx';
Also, are you signing the transaction before connecting to infura. You need to sign transaction for address before making any transaction request. You can use HD-wallet-provider and use mnemonic which was provided to you during your account creation.
Related
I am trying to implement MSAL to a xamarin windows app. When im trying to use AcquireTokenInteractive it gives me this error.
" {"Only loopback redirect uri is supported, but urn:ietf:wg:oauth:2.0:oob was found. Configure http://localhost or http://localhost:port
both during app registration and when you create the PublicClientApplication object. See https://aka.ms/msal-net-os-browser for details"} "
CODE:
`app = PublicClientApplicationBuilder.Create(ClientId)
.WithBroker()
.Build();
System.Collections.Generic.IEnumerable accounts = await app.GetAccountsAsync();
AcquireTokenInteractiveParameterBuilder interactiveRequest = await app.AcquireTokenInteractive(GetScopes).WithAccount(accounts.FirstOrDefault()).ExecuteAsync();`
AND in Azure AD i have added the below redirecr Uri;
"ms-appx-web://microsoft.aad.brokerplugin/{sid}"
This worked for me when i was working on the feature branch and now when i have merged this into the master, it's not working.
I want to create a passwordless authentication (using Metamask to sign a message; then validate the message on the server and then assign a JWT token). I want the part for signing a message to be written inside a vanilla JavaScript file.
Most of the articles I see online are from 2018 and talk about using web3.eth.personal.sign method from web3 which being injected into the browser by Metamask. However I understand this is no longer the case with Metamask. Now that web3 is not injected anymore, what functions do I call to sign a message with Metamask?
What I've attempted...
I understand there's a window.ethereum object injected into the browser but I can't seem to find an equivalent function in the Metamask documentation for web3.eth.personal.sign
I'm guessing the alternative is to use web3 without window.ethereum but how to I inject this into a vanilla JavaScript file? Also how do I ensure that the message is signed by Metamask if I just use web3 as standalone?
You could use the web3 npm package. Then you can connect it to Metamask with:
import Web3 from "web3";
window.ethereum.request({ method: "eth_requestAccounts" });
const web3 = new Web3(window.ethereum);
This will make metamask popup and ask the user to select an account.
Then to sign a message you can call web3 with:
const dataToSign = "My test message";
const accounts = await web3.eth.getAccounts();
const signature = await web3.eth.sign(dataToSign, accounts[0]);
Documentation: https://web3js.readthedocs.io/en/v1.3.4/web3-eth.html#sign
This will cause Metamask to ask the user to sign the data with their currently active account. I'm not sure how to validate if the signature is correct.
I have faced a problem to refresh google access token on server side.
RestTemplate restTemplate = new RestTemplate();
MultiValueMap<String, String> params = new LinkedMultiValueMap();
params.add("client_id", clientSecrets.getDetails().getClientId());
params.add("client_secret", clientSecrets.getDetails().getClientSecret());
params.add("refresh_token", this.refreshToken);
params.add("grant_type", "refresh_token");
String result = restTemplate.postForObject(requestUrl, params, String.class);
Response I got from google authentication server is just 403 status code.
and message is like this
{"error":"internal_failure","error_description":"SSL is required to perform this operation."}
Is that compulsory to use SSL on my server just in order to refresh access token ?
It's been tested on my local server and does not attach any SSL to it.
References for this code is from below URL.
https://developers.google.com/identity/protocols/OAuth2WebServer#offline
I solved this issue by adding 'https' protocol instead of 'http' protocol for google api
I had called like
http://www.googleapis.com/oauth2/v4/token
but for SSL call
https://www.googleapis.com/oauth2/v4/token
is required to refresh access token
As per my requirement, I am using WL.APP.setServerURL before every login request WLAuthorizationManager.loginof mobilefirst.
When I do first an valid/Invalid login attempt it works fine. As on next attempt I do WL.App.setServerURL, and then WLAuthorizationManager.login (login request) OR WLAuthorizationManager.obtainAccessToken (obtain access token request) don't respond anything. No success and no fail. Although non-secure adapter method works fine.
If I do WL.APP.setServerURL only once on application startup, everything works fine but in between call cause application failure.
let url = ... //fetcht url from adapter call
WL.App.setServerUrl(url, function (sucess) {
WLAuthorizationManager.login(securityCheckName, loginParam).then((data) => {
.... //After login code
}, (response) => {
//Login fail code
});
}, function (error) {
});
Flow :-
I call above code on click of login button.I call a method to get server url from adapter first then I set that url as server url.
When I do an invalid attempt of login it works find for first time, and on next call MFP login, it doesn't respond. Not success nor fail in application.
I am getting error in native logs android.
Android Error logs :-
E/SecurityCheckChallengeHandler(30199): SecurityCheckChallengeHandler.submitChallengeAnswer in SecurityCheckChallengeHandler.java:51 :: submitAnswer has been called for unknown request
.
MobileFirst server version :- 8.0.0.00-20170911-123510
MobileFirst Cordova(plugin) version :- 8.0.2017102403
The WL.App.setServerUrl API is meant to be used sparingly whenever the app needs to connect to a server other than the one defined in mfpclient.properties. If you want to keep the server URL constant, you should just put it up in the mfpclient.properties.
Having said that, the behaviour you mention is not expected - can you update your question with a code snippet of your app performing login & setServerUrl
I am trying to connect to Google via OAuth2. I am using code which works in another application, so I am quite sure the problem is in the configuration at Google.
I registered a client-id and secret-key in the Google Console which I added to the authorization config:
var client = new GoogleOAuth2Client("[client id].apps.googleusercontent.com", "[secret key]");
var extraData = new Dictionary<string, object>();
OAuthWebSecurity.RegisterClient(client, "Google", extraData);
Unfortunately, when I press the button to connect I get the following error:
That’s an error.
Error: invalid_request
Invalid parameter value for redirect_uri: Missing authority: file:///Account/ExternalLoginCallback%3FReturnUrl=/Request Details scope=https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email
response_type=code
redirect_uri=file:///Account/ExternalLoginCallback%3FReturnUrl=/
state=provider=google&sid=[numbers]
client_id=[client id].apps.googleuserconte
I've tried changing the localhost parameter in /etc/hosts file to other base URLs and I've added these locations to redirect URIs in Google Console as follows:
http://localhost:8080/Account/ExternalLoginCallback%3FReturnUrl=/
http://localhost.example.com:8080/Account/ExternalLoginCallback
http://localhost.example.com:8080/Account/ExternalLoginCallback%3FReturnUrl=/
The error persists. I don't know what the problem can be and I hope someone can give me some guidance. Thanks
The value of the redirect_uri parameter in the authorization request that is sent to Google upon pressing the button to connect must be set to one of the values that you have registered for you client in the Google API Console. So instead of passing:
file:///Account/ExternalLoginCallback%3FReturnUrl=/
you should pass e.g.
http://localhost:8080/Account/ExternalLoginCallback%3FReturnUrl=/
but properly URL-encoded so:
http%3A%2F%2Flocalhost%3A8080%2FAccount%2FExternalLoginCallback%253FReturnUrl%3D%2F
See sample code at: https://github.com/mj1856/DotNetOpenAuth.GoogleOAuth2/blob/master/DotNetOpenAuth.GoogleOAuth2/GoogleOAuth2Client.cs