Flutter api calls oauth_signature HMAC-SHA1 generation

174 Views Asked by At

I am trying to make an API call to my server everything works properly on postman but I can't seem to get it going on Flutter

                      String oauthConsumer ='oauth_consumer_key=[MyKey]';
                      String oauthNonce =
                          'oauth_nonce=${Random().nextInt(4294967296).toString()}';
                      String oauthCallback =
                          'oauth_callback=[MyCallback address]';
                      String oauthVersion = 'oauth_version=1.0';
                      String oauthTime =
                          'oauth_timestamp=${(DateTime.now().millisecondsSinceEpoch ~/ 1000).toString()}';
                      String oauthMethod = 'oauth_signature_method=HMAC-SHA1';

                      var oauthList = [
                        oauthCallback,
                        oauthConsumer,
                        oauthNonce,
                        oauthMethod,
                        oauthTime,
                        oauthVersion
                      ];
                      oauthList.sort();
                      String oauthSig = //[I need a method to create this properly]

                      var request = http.Request('POST', Uri.parse([My URL]));
                      http.StreamedResponse response = await request.send();

                      if (response.statusCode == 200) {
                        print(await response.stream.bytesToString());
                      }

Like I mention postman does return the token and the token secret but trying on Flutter returns the Authentication Required error

Picture of the Postman request body

enter image description here

On the Authorization tab just filled in the Consumer Key and the Consumer Secret the headers where left untouched and default like this:

enter image description here

0

There are 0 best solutions below