getLensAccessToken method
Implementation
Future<Map<String, String>> getLensAccessToken(
String signature, String address) async {
try {
final Map<String, String> headers = {'Content-Type': 'application/json'};
final Map<String, dynamic> requestBody = {
'query': '''
mutation (\$request: SignedAuthChallenge!) {
authenticate(request: \$request) {
accessToken
refreshToken
}
}
''',
'variables': {
'request': {'address': address, 'signature': signature},
},
};
final response = await http.post(
Uri.parse('https://api.lens.dev/'),
headers: headers,
body: jsonEncode(requestBody),
);
if (response.statusCode == 200) {
final Map<String, dynamic> responseData = jsonDecode(response.body);
final String accessToken =
responseData['data']['authenticate']['accessToken'] as String;
return {'accessToken': accessToken};
} else {
throw Exception('error getting lens access token');
}
} catch (error) {
throw Exception('error getting lens access token $error');
}
}