Please I would really appreciate if anyone can explain how to use the below code in flitter.
curl -k -d "grant_type=password&username=Username&password=Password"
-H "Authorization: Basic Base64(consumer-key:consumer-secret)"
https://devesb.elicia.systems:8263/token
The above cURL command shows how to generate an access token using the Password Grant type.
That was what they said, Then I was given this:
curl -k -X POST "https://devesb.vfdbank.systems:8263/vfd-wallet/1.1/wallet2/onboarding?wallet-credentials=wallet-credentials" -H "accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer c9b84e30-e59a-3789-b6d1-3595552dfb23" -d "{ \"username\": \"Username used to signup\", \"walletName\": \"Company/Wallet name\", \"webhookUrl\": \"Inward notifications Webhook\", \"shortName\": \"Wallet short name (4 Characters)\", \"implementation\": \"POOL or 1-1\"}"
was also given a consumer key and consumer secret key. Could you please help me structure the above curl (The one I was given) and tell me where to add the consumer and secret keys. Have been on this for weeks now and I would be so very grateful if you could help me out on this.
CodePudding user response:
You'll need to use the http package.
Here is a more or less straightforward translation of your code:
// Required for base64encode and utf8 encoding
import 'dart:convert';
import 'package:http/http.dart' as http;
void forExample() async {
final testUsername = 'username';
final testPassword = 'password';
final uri = Uri.parse('https://devesb.elicia.systems:8263/token');
final token = base64Encode(utf8.encode('$testUsername:$testPassword'));
final response = await http.post(
uri,
headers: {
'Authorization': 'Basic $token',
},
body: {
'grant_type': 'password',
'username': testUsername,
'password': testPassword,
},
);
print(response.body);
}
Note: In the above code, the request body will be automatically encoded as x-www-form-urlencoded, as in your curl request.
CodePudding user response:
curl -k -d "grant_type=password&username=Username&password=Password"
-H "Authorization: Basic Base64(consumer-key:consumer-secret)"
https://devesb.elicia.systems:8263/token
The above cURL command shows how to generate an access token using the Password Grant type.
That was what they said (The API providers), Then I was given the below Curl:
curl -k -X POST "https://devesb.vfdbank.systems:8263/vfd-wallet/1.1/wallet2/onboarding?wallet-credentials=wallet-credentials" -H "accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer c9b84e30-e59a-3789-b6d1-3595552dfb23" -d "{ \"username\": \"Username used to signup\", \"walletName\": \"Company/Wallet name\", \"webhookUrl\": \"Inward notifications Webhook\", \"shortName\": \"Wallet short name (4 Characters)\", \"implementation\": \"POOL or 1-1\"}"
was also given a consumer key and consumer secret key. Could you please help me structure the above curl (The one I was given) and tell me where to add the consumer and secret keys. Have been on this for weeks now and I would be so very grateful if you could help me out on this.