- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已实现 使用 Firebase 身份验证的 google 登录 在我的 Android 应用程序中成功。
如您所见,我已使用我的帐户登录并显示在 Firebase 控制台上。
函数 firebaseAuthWithGoogle 使用 Google Sign-in 登录后,使用 Firebase 对用户进行身份验证:
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
mFirebaseAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "signInWithCredential:success");
final FirebaseUser user = mFirebaseAuth.getCurrentUser();
//This is to connect to the http server and save the user data in my MySql database
FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(LoginActivity.this, new OnSuccessListener<InstanceIdResult>() {
@Override
public void onSuccess(InstanceIdResult instanceIdResult) {
String userToken = instanceIdResult.getToken();
String uid = user.getUid();
String name = user.getDisplayName();
String email = user.getEmail();
String profileUrl = user.getPhotoUrl().toString();
String coverUrl = "";
UserInterface userInterface = ApiClient.getApiClient().create(UserInterface.class);
Call<Integer> call = userInterface.signin(new LoginActivity.UserInfo(uid,name,email,profileUrl,coverUrl,userToken));
call.enqueue(new Callback<Integer>() {
@Override
public void onResponse(Call<Integer> call, Response<Integer> response) {
progressDialog.dismiss();
Toast.makeText(LoginActivity.this,"Login succesfull AFTER API CALL",Toast.LENGTH_SHORT).show();
startActivity(new Intent(LoginActivity.this,MainActivity.class));
finish();
}
@Override
public void onFailure(Call<Integer> call, Throwable t) {
progressDialog.dismiss();
Toast.makeText(LoginActivity.this,"Login failed AFTER API CALL",Toast.LENGTH_SHORT).show();
}
});
}
});
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "signInWithCredential:failure", task.getException());
}
// ...
}
});
}
//This is to connect to the http server and save the user data in my MySql database
FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(LoginActivity.this, new OnSuccessListener<InstanceIdResult>() {
@Override
public void onSuccess(InstanceIdResult instanceIdResult) {
String userToken = instanceIdResult.getToken();
String uid = user.getUid();
String name = user.getDisplayName();
String email = user.getEmail();
String profileUrl = user.getPhotoUrl().toString();
String coverUrl = "";
UserInterface userInterface = ApiClient.getApiClient().create(UserInterface.class);
Call<Integer> call = userInterface.signin(new LoginActivity.UserInfo(uid,name,email,profileUrl,coverUrl,userToken));
call.enqueue(new Callback<Integer>() {
@Override
public void onResponse(Call<Integer> call, Response<Integer> response) {
progressDialog.dismiss();
Toast.makeText(LoginActivity.this,"Login succesfull AFTER API CALL",Toast.LENGTH_SHORT).show();
startActivity(new Intent(LoginActivity.this,MainActivity.class));
finish();
}
@Override
public void onFailure(Call<Integer> call, Throwable t) {
progressDialog.dismiss();
Toast.makeText(LoginActivity.this,"Login failed AFTER API CALL",Toast.LENGTH_SHORT).show();
}
});
}
});
}
Toast.makeText(LoginActivity.this,"Login failed AFTER API CALL",Toast.LENGTH_SHORT).show();
ApiClient.java
public static Retrofit getApiClient(){
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient httpClient = new OkHttpClient.Builder()
.addInterceptor(httpLoggingInterceptor)
.build();
if(retrofit==null){
retrofit = new Retrofit.Builder().baseUrl(BASE_URL)
.client(httpClient)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
D/OkHttp: --> POST http://10.0.2.2/friendster/public/app/login
Content-Type: application/json; charset=UTF-8
Content-Length: 413
D/OkHttp: {"CoverUrl":"","email":"MyEmail@gmail.com","name":"Ahmed Ghrib","profileUrl":"https://lh6.googleusercontent.com/-S8l_5gZaXJ8/AAAAAAI/AAAAAAAAAAA/ACHi3rfObo6-Ta-wxrMUvcAZ8Yg/s96-c/photo.jpg","uid":"YACACYYDcGVr26N8OHuTuQlQqvU2","userToken":"ecxdtFaKldI:APA91bHb1PAA5hU6i1oMqnSsDXXkAaXNb6dynyaYmhU_soHTWmLXud6REjCpqTjsGpgdBh1NMYUqAr3SaTUWapN4v73zkvyYD2f3yegUP3H38eeU_JtH7NOSMKbF4U"}
D/OkHttp: --> END POST (413-byte body)
W/e.myapplicatio: Verification of okhttp3.internal.http.ExchangeCodec okhttp3.internal.connection.RealConnection.newCodec$okhttp(okhttp3.OkHttpClient, okhttp3.Interceptor$Chain) took 134.353ms
D/OkHttp: <-- HTTP FAILED: java.net.UnknownServiceException: CLEARTEXT communication to 10.0.2.2 not permitted by network security policy
CLEARTEXT communication to 10.0.2.2 not permitted by network security policy
src/main/res/xml/network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">api.example.com(to be adjusted)</domain>
</domain-config>
</network-security-config>
<application
---
android:networkSecurityConfig="@xml/network_security_config">
CLEARTEXT communication to 10.0.2.2 not permitted by network security policy
最佳答案
将其用于安全配置文件:
src/main/res/xml/network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<!--Set application-wide security config using base-config tag.-->
<base-config cleartextTrafficPermitted="true"/>
</network-security-config>
关于android-studio - OkHttp:<-- HTTP 失败:java.net.UnknownServiceException:网络安全策略不允许与 10.0.2.2 的 CLEARTEXT 通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59856341/
在iOS开发中,保障应用的网络安全是一个非常重要的环节。以下是一些常见的网络安全措施及对应的示例代码: Swift版 1. 使用HTTPS 确保所有的网络请求使用HTTPS协议,以加密数据传输,
如何在 Java 中为椭圆曲线加密生成曲线点? 最佳答案 建议您考虑使用 bouncycastle java libary ,它支持椭圆曲线和 Java ME。在他们的 latest releases
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 11 年前关闭。 Improve this
因此,您总是会听到很多有关网站变得流行,然后遭到黑客攻击的故事。基本上,我将在几周内发布(作为唯一的程序员)一个网站。它是用 MVC2 制作的,将在 Azure 云上运行。 我只是想知道哪些类型的东西
我有一个登录页面 (welcome-page.jsp),它检查用户是否存在于数据库中。如果他提供的密码正确且类型正确,他将被重定向到一个页面。现在我想在发送数据时增加一些安全性。我是新来的...这是登
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
我正在尝试通过具有多个源地址的 Terraform 为 Azure 中的网络安全组配置网络安全规则。 基于文档 https://www.terraform.io/docs/providers/azur
我正在开发一个从文本(TTS)生成音频并为用户提供速度/音高控制的播放器的项目。 我的问题与请求安全有关。 用户在我的网站注册时获得了 widget_id,他放了一些 js在他的网站上,而 api 在
我正在关注基于 spring 框架 3.2.4 的应用程序的本教程 http://springdiaries.blogspot.be/2012/12/web-security-preventing-c
我目前已经构建了一个系统来检查用户 IP、浏览器和随机字符串 cookie 以确定他是否是管理员。 在最坏的情况下,有人会窃取我的 cookie,使用与我相同的浏览器,并掩盖他的 IP 以显示为我的
TL;DR 通过网络策略来提升网络安全,可以极大降低了实现和维护的成本,同时对系统几乎没有影响。 尤其是基于 eBPF 技术的 Cilium,解决了内核扩展性不足的问题,从内核层面为工作负载
我允许用户从我的应用程序下载文件。为此,我根据文件类型明确将“Content-Disposition”设置为“内联”或“附件”。现在这有点手册。因此,对于 pdf 文件,我将其设置为“内联”,但对于
我有一个 MEAN 堆栈应用程序,带有类似 API 的 REST。我有两种用户类型:用户和管理员。为了让用户登录并保持 session ,我像这样使用 jsonwebtoken jwt(简化): co
我是一名优秀的程序员,十分优秀!