Flutter中OAuth1三方认证调用Schoology API失败求助
Schoology API三腿OAuth1认证Flutter实现失败,报错"Bad state: "
我持有Schoology学生账号,已获取该API的consumer token和secret,且在Postman中验证双腿OAuth1认证可正常调用接口。但在Flutter中使用oauth1 Dart包实现三腿OAuth1认证时始终失败,持续收到错误提示Bad state: ,无法按预期打印收件箱消息。
用户点击按钮时会触发以下测试代码(注:生产环境不会硬编码密钥或使用print方法):
void stepOne() { final oauth1.Platform platform = oauth1.Platform( 'https://api.schoology.com/v1/oauth/request_token', 'https://api.schoology.com/v1/oauth/authorize', 'https://api.schoology.com/v1/oauth/access_token', oauth1.SignatureMethods.hmacSha1 ); //define consumer key and secret (in my actual code both are obviously included) const String consK = "--CENSORED--"; const String consS = "--CENSORED--"; final oauth1.ClientCredentials clientCredentials = oauth1.ClientCredentials(consK, consS); final oauth1.Authorization auth = oauth1.Authorization(clientCredentials, platform); // request temporary credentials auth.requestTemporaryCredentials('oob').then((res) { // redirect to authorization page print('Open with your browser: ${auth.getResourceOwnerAuthorizationURI(res.credentials.token)}'); // get verifier (PIN) stdout.write('PIN: '); String verifier = stdin.readLineSync() ?? ''; // request token credentials (access tokens) return auth.requestTokenCredentials(res.credentials, verifier); }).then((res) { // you've got token credentials // create Client object final oauth1.Client client = oauth1.Client( platform.signatureMethod, clientCredentials, res.credentials ); // now you can access protected resources via client client.get(Uri.parse('https://api.schoology.com/v1/messages/inbox')).then((res) { print('API Response: ${res.body}'); }); // You can get optional values from AuthorizationResponse object if needed // print('Your screen name is ${res.optionalParameters['screen_name']}'); }).catchError((error) { print('Error during OAuth process: $error'); }); }
求有OAuth1或Schoology API使用经验的开发者帮忙排查问题,谢谢!
内容的提问来源于stack exchange,提问作者Ari S
相关产品推荐
相关产品推荐

