We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Here’s the code I’m using:
import 'dart:convert'; import 'package:casdoor_flutter_sdk/casdoor_flutter_sdk.dart'; import 'package:flutter/material.dart'; import 'package:http/http.dart'; import 'package:shared_preferences/shared_preferences.dart'; final AuthConfig authConfig = AuthConfig( clientId: "", serverUrl: "", organizationName: "", appName: "", callbackUrlScheme: "", redirectUri: "", ); final Casdoor casdoor = Casdoor(config: authConfig); class AuthModel with ChangeNotifier { bool isAuthenticated = false; String? username; String? id; String accessToken = ""; AuthModel() { init(); } Future<void> init() async { // pass notifyListeners(); } Future<void> signIn(BuildContext buildContext) async { String result = ""; try { result = await casdoor.showFullscreen(buildContext); debugPrint("result: $result"); final String code = Uri.parse(result).queryParameters["code"] ?? ""; final Response response = await casdoor.requestOauthAccessToken(code); accessToken = jsonDecode(response.body)["access_token"] as String; SharedPreferences prefs = await SharedPreferences.getInstance(); await prefs.setString("accessToken", accessToken); isAuthenticated = true; await fetchInfos(); } catch (e) { debugPrint(e.toString()); } notifyListeners(); } Future<void> signOut() async { await casdoor.tokenLogout(accessToken, "", "logout", clearCache: true); SharedPreferences prefs = await SharedPreferences.getInstance(); await prefs.remove("accessToken"); isAuthenticated = false; notifyListeners(); } Future<void> fetchInfos() async { final Response response = await casdoor.getUserInfo(accessToken); debugPrint(response.body); notifyListeners(); } }
When calling fetchInfos, the output is consistently:
fetchInfos
I/flutter ( 6479): { I/flutter ( 6479): "status": "error", I/flutter ( 6479): "msg": "Unauthorized operation", I/flutter ( 6479): "data": null, I/flutter ( 6479): "data2": null I/flutter ( 6479): }
Looking at the getUserInfo method in the Casdoor Flutter SDK, it makes a POST request to /api/userinfo:
getUserInfo
/api/userinfo
Future<http.Response> getUserInfo(String accessToken) async { return await http.post( Uri( scheme: parseScheme(), host: parseHost(), port: parsePort(), path: 'api/userinfo', ), headers: {'Authorization': 'Bearer $accessToken'}, ); }
However, upon reviewing the Swagger API documentation at [this link](https://demo.casdoor.com/swagger/#/Account%20API/ApiController.UserInfo), it indicates that /api/userinfo should be a GET request, not a POST request.
Should the getUserInfo method in the SDK be modified to use a GET request instead of POST?
The text was updated successfully, but these errors were encountered:
I’ve submitted a PR to address this issue: #46
Could you confirm if the change to GET is correct?
Sorry, something went wrong.
hsluoyz
Successfully merging a pull request may close this issue.
Code Example
Here’s the code I’m using:
Problem
When calling
fetchInfos
, the output is consistently:Investigation
Looking at the
getUserInfo
method in the Casdoor Flutter SDK, it makes a POST request to/api/userinfo
:However, upon reviewing the Swagger API documentation at [this link](https://demo.casdoor.com/swagger/#/Account%20API/ApiController.UserInfo), it indicates that
/api/userinfo
should be a GET request, not a POST request.Question
Should the
getUserInfo
method in the SDK be modified to use a GET request instead of POST?The text was updated successfully, but these errors were encountered: