BitmojiApiResponseInterceptor.java
3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.bitstrips.imoji.api;
import android.content.Context;
import android.text.TextUtils;
import com.bitstrips.imoji.monouser.api.TokenErrorResponse;
import com.bitstrips.imoji.monouser.controllers.UserLogoutController;
import com.bitstrips.imoji.monouser.oauth2.OAuth2Manager;
import com.bitstrips.imoji.monouser.oauth2.OAuth2Manager.OnOAuth2TokenRefreshCallback;
import com.bitstrips.imoji.ui.BitmojiBaseActivity;
import com.google.gson.Gson;
import com.squareup.okhttp.Interceptor;
import com.squareup.okhttp.Interceptor.Chain;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.squareup.okhttp.ResponseBody;
import dagger.Lazy;
import java.io.IOException;
import javax.inject.Inject;
public class BitmojiApiResponseInterceptor
implements Interceptor
{
private static final String FORCE_LOGOUT_ERROR = "force_logout";
private static final String INVALID_TOKEN_ERROR = "invalid_token";
private static final String TAG = "ApiResponseInterceptor";
private final Context mContext;
private final OAuth2Manager mOAuth2Manager;
private final Lazy<UserLogoutController> mUserLogoutController;
@Inject
public BitmojiApiResponseInterceptor(Context paramContext, OAuth2Manager paramOAuth2Manager, Lazy<UserLogoutController> paramLazy)
{
this.mContext = paramContext;
this.mOAuth2Manager = paramOAuth2Manager;
this.mUserLogoutController = paramLazy;
}
private boolean isForceLogoutError(TokenErrorResponse paramTokenErrorResponse)
{
return (paramTokenErrorResponse != null) && (!TextUtils.isEmpty(paramTokenErrorResponse.getMessage())) && (TextUtils.equals(paramTokenErrorResponse.getMessage().toLowerCase(), "force_logout"));
}
private boolean isInvalidTokenError(TokenErrorResponse paramTokenErrorResponse)
{
return (paramTokenErrorResponse != null) && (!TextUtils.isEmpty(paramTokenErrorResponse.getMessage())) && (TextUtils.equals(paramTokenErrorResponse.getMessage().toLowerCase(), "invalid_token"));
}
public Response intercept(Interceptor.Chain paramChain)
throws IOException
{
Object localObject = paramChain.request();
paramChain = paramChain.proceed((Request)localObject);
if (!TextUtils.isEmpty(((Request)localObject).header("authorization")))
{
if ((paramChain == null) || (paramChain.body() == null)) {
return paramChain;
}
if (paramChain.code() == 401)
{
localObject = (TokenErrorResponse)new Gson().fromJson(paramChain.body().charStream(), TokenErrorResponse.class);
if (!isInvalidTokenError((TokenErrorResponse)localObject)) {
break label98;
}
this.mOAuth2Manager.forceRefreshToken(new OAuth2Manager.OnOAuth2TokenRefreshCallback()
{
public void onTokenRefreshFailed(boolean paramAnonymousBoolean)
{
if (paramAnonymousBoolean) {
BitmojiBaseActivity.sendShowForceLogoutDialogBroadcast(BitmojiApiResponseInterceptor.this.mContext);
}
}
public void onTokenRefreshSucceeded(boolean paramAnonymousBoolean) {}
});
}
}
for (;;)
{
return paramChain;
label98:
if (isForceLogoutError((TokenErrorResponse)localObject))
{
((UserLogoutController)this.mUserLogoutController.get()).logout();
BitmojiBaseActivity.sendShowForceLogoutDialogBroadcast(this.mContext);
continue;
if (paramChain.code() == 401)
{
((UserLogoutController)this.mUserLogoutController.get()).logout();
BitmojiBaseActivity.sendShowForceLogoutDialogBroadcast(this.mContext);
}
}
}
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/com/bitstrips/imoji/api/BitmojiApiResponseInterceptor.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/