Created
January 2, 2020 09:32
-
-
Save manhduy/ace7eee7a7835ed0f11a2f16e50854b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<Response> get(String url) async { | |
String wsseHeader = await generateAuthHeader(); | |
final response = await httpClient.get(url, | |
headers: { | |
HttpHeaders.contentTypeHeader: 'application/vnd.api+json', | |
'Authorization': 'WSSE profile="UsernameToken"', | |
'X-WSSE': wsseHeader | |
}, | |
); | |
return response; | |
} | |
Future<String> generateAuthHeader() async { | |
String userName = 'username'; | |
String apiKey = 'apikey'; | |
var uuid = Uuid(); | |
String md5Str = md5.convert(utf8.encode(uuid.v1())).toString(); | |
String none = base64.encode(utf8.encode(md5Str)); | |
String created = DateTime.now().toUtc().toIso8601String(); | |
String input = utf8.decode(base64.decode(none)) + | |
created + apiKey; | |
String digest = base64.encode(sha1.convert(utf8.encode(input)).bytes); | |
String wsseHeader = 'UsernameToken Username="$userName", PasswordDigest="$digest", Nonce="$none", Created="$created"'; | |
return wsseHeader; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Flutter - Genearate WSSE header
Flutter http does not support to generate WSSE header. These above code is used for generate the header for http request. I converted from php code:
https://doc.oroinc.com/backend/api/using/how-to-use-wsse-authentication/#header-generation