只需一张地图即可存储帖子请求正文
var rqstParameters = {
'email': '',
'loginMethod': '',
'name': '',
'token': ''
};
按下此按钮后触发了Google登录
return RaisedButton(
onPressed: () {
authService.googleSignIn().then((user) {
user.getIdToken(refresh: true).then((usrTokenId) {
rqstParameters['email'] = user.email;
rqstParameters['loginMethod'] = '4';
rqstParameters['name'] = user.displayName;
// printWrapped(usrTokenId.token);
rqstParameters['token'] = usrTokenId.token;
}).whenComplete(() {
fetchPost().then((response) {
var body = response.body;
print(body);
});
});
});
},
color: Colors.transparent,
child: Text(
'Signin with GOOGLE',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
);
请求看起来像这样--->
Future<http.Response> fetchPost() async {
// print(rqstParameters);
final response = await http.post(
'https://this/is/the_server.in/dashboard/login.php',
headers: {'Accept': 'application/json'},
body: rqstParameters,
);
print(response.statusCode);
return response;
}
这是用于Google登录的身份验证逻辑
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:rxdart/rxdart.dart';
class AuthService {
FirebaseUser mCurrentUser;
final GoogleSignIn _googleSignIn = GoogleSignIn();
final FirebaseAuth _auth = FirebaseAuth.instance;
// Shared State for Widgets
Observable<FirebaseUser> user; // firebase
PublishSubject loading = PublishSubject();
// constructor
AuthService() {
user = Observable(_auth.onAuthStateChanged);
}
Future<FirebaseUser> googleSignIn() async {
loading.add(true);
final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
final GoogleSignInAuthentication googleAuth =
await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
final AuthResult result = await _auth.signInWithCredential(credential);
final FirebaseUser user = result.user;
// Done
loading.add(false);
print("signed in as " + user.displayName );
return user;
}
void signOut() {
_auth.signOut();
}
final AuthService authService = AuthService();
这是我从服务器获取的响应正文->
{"email":"example@question.com","name":"Users Display Name","token":"eyJhbGciOiJSUzI1NiIsImtpZCI6IjI1MDgxMWNkY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hfuCMgUISseyl-ol5Ua_RnE7KHwdjNxTvVdnax_cT42uY88cpGGQc3JksdjhfrKAvTe19dzu092kMVnG91euFMBUQw2Nu6a6cdq7k4vz-egZd1IMIwkrmSQiRQihG3ODEOhPPuuo2lEsO7iHMldF3c4D_oA","payload":false,"error":"payload not verified"}
服务器使用此PHP代码验证客户端
$client = new Google_Client(['client_id' => $CLIENT_ID]);
$payload = $client->verifyIdToken($id_token);
if ($payload) {
//login Successful
} else {
// payload not verified
// login Failed
}
为什么当令牌都正确发送并保持适当的流量时,有效载荷未得到验证...请帮助..:(