
[英]I am developing an android app for job search .here i am using PHP as back end
[英]i am developing an android mobile app which loggin in using email but i want to change it with mobile phone but it gives error 401unauthorised
我正在开发一个 android 移动应用程序,它使用 email 登录,但我想使用电话号码登录。 当我转换电话号码登录的东西时,它会出现 401 未经授权的错误,请帮助我。 我正在使用 OAuth 身份验证。
这是一些错误详细信息..
401 未经授权http://phplaravel-528344-1682591.cloudwaysapps.com/api/user/oauth/token (769ms)
{错误用户凭据不正确错误描述用户凭据不正确消息用户凭据不正确}
这是我的 android 部分..
HashMap<String, Object> map = new HashMap<>();
map.put("grant_type", "password");
map.put("username", mobile);
map.put("password", password.getText().toString());
map.put("client_secret", BuildConfig.CLIENT_SECRET);
map.put("client_id", BuildConfig.CLIENT_ID);
map.put("device_token", SharedHelper.getKey(this, "device_token", "No device"));
map.put("device_id", SharedHelper.getKey(this, "device_id", "123"));
map.put("device_type", BuildConfig.DEVICE_TYPE);
这是我的 api 文件的登录 function 授予登录访问令牌
public function login(Request $request)
{
$tokenRequest = $request->create('/oauth/token', 'POST', $request->all());
$request->request->add([
"client_id" => $request->client_id,
"client_secret" => $request->client_secret,
"grant_type" => 'password',
"code" => '*',
]);
$response = Route::dispatch($tokenRequest);
$json = (array)json_decode($response->getContent());
if (!empty($json['error'])) {
$json['error'] = $json['message'];
}
if (empty($json['error'])) {
if (Auth::guard("web")->attempt(['email' => $request->username, 'password' => $request->password])) {
$user = Auth::guard("web")->user();
if ($user) {
$accessTokens = DB::table('oauth_access_tokens')->where('user_id', $user->id)->orderBy('created_at', 'desc')->get();
$t = 1;
foreach ($accessTokens as $accessToken) {
if ($t != 1) {
DB::table('oauth_refresh_tokens')->where('access_token_id', $accessToken->id)->delete();
DB::table('oauth_access_tokens')->where('id', $accessToken->id)->delete();
}
$t++;
}
}
}
}
// $json['status'] = true;
$response->setContent(json_encode($json));
$update = User::where('mobile', $request->username)->update(['device_token' => $request->device_token, 'device_id' => $request->device_id, 'device_type' => $request->device_type]);
return $response;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.