正在查看: Meine NEW v2.0.3616 应用的 BrowserAuthorizationFragment.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Meine NEW v2.0.3616 应用的 BrowserAuthorizationFragment.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.microsoft.identity.common.internal.providers.oauth2;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import com.microsoft.identity.common.adal.internal.AuthenticationConstants;
import com.microsoft.identity.common.adal.internal.util.StringExtensions;
import com.microsoft.identity.common.exception.ClientException;
import com.microsoft.identity.common.exception.ErrorStrings;
import com.microsoft.identity.common.internal.logging.Logger;
import com.microsoft.identity.common.internal.telemetry.Telemetry;
import com.microsoft.identity.common.internal.telemetry.events.UiEndEvent;
import com.microsoft.identity.common.internal.ui.webview.AzureActiveDirectoryWebViewClient;
import com.microsoft.identity.common.internal.util.StringUtil;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
public class BrowserAuthorizationFragment extends AuthorizationFragment {
private static final String BROWSER_FLOW_STARTED = "browserFlowStarted";
private static final String TAG = "BrowserAuthorizationFragment";
private static Class<?> sCallingActivityClass;
private static String sCustomTabResponseUri;
private Intent mAuthIntent;
private boolean mBrowserFlowStarted = false;
private void completeAuthorizationInBrowserFlow(String str) {
String str2 = TAG;
Logger.info(str2, null, "Received redirect from customTab/browser.");
Intent createResultIntent = createResultIntent(str);
HashMap<String, String> urlParameters = StringExtensions.getUrlParameters(str);
String str3 = urlParameters.get("username");
if (isDeviceRegisterRedirect(str) && !TextUtils.isEmpty(str3)) {
Logger.info(str2, " Device needs to be registered, sending BROWSER_CODE_DEVICE_REGISTER");
Logger.infoPII(str2, "Device Registration triggered for user: " + str3);
createResultIntent.putExtra("username", str3);
sendResult(AuthenticationConstants.UIResponse.BROWSER_CODE_DEVICE_REGISTER, createResultIntent);
return;
}
if (urlParameters.containsKey(AuthenticationConstants.Broker.INSTALL_URL_KEY)) {
startActivity(new Intent("android.intent.action.VIEW", Uri.parse(urlParameters.get(AuthenticationConstants.Broker.INSTALL_URL_KEY))));
Logger.info(str2, "Return to caller with BROKER_REQUEST_RESUME, and waiting for result.");
sendResult(AuthenticationConstants.UIResponse.BROKER_REQUEST_RESUME, createResultIntent);
} else if (!StringUtil.isEmpty(createResultIntent.getStringExtra(AuthenticationConstants.AuthorizationIntentKey.AUTHORIZATION_FINAL_URL))) {
sendResult(AuthenticationConstants.UIResponse.BROWSER_CODE_COMPLETE, createResultIntent);
Telemetry.emit(new UiEndEvent().isUiComplete());
} else if (StringUtil.isEmpty(createResultIntent.getStringExtra(AuthenticationConstants.Browser.RESPONSE_ERROR_SUBCODE)) || !createResultIntent.getStringExtra(AuthenticationConstants.Browser.RESPONSE_ERROR_SUBCODE).equalsIgnoreCase(AuthenticationConstants.Browser.SUB_ERROR_UI_CANCEL)) {
Telemetry.emit(new UiEndEvent().isUiCancelled());
sendResult(AuthenticationConstants.UIResponse.BROWSER_CODE_ERROR, createResultIntent);
} else {
Telemetry.emit(new UiEndEvent().isUserCancelled());
sendResult(AuthenticationConstants.UIResponse.BROWSER_CODE_SDK_CANCEL, createResultIntent);
}
finish();
}
public static Intent createCustomTabResponseIntent(Context context, String str) {
if (sCallingActivityClass == null) {
Logger.warn(TAG, "Calling activity class is NULL. Unable to create intent for response.");
return null;
}
sCustomTabResponseUri = str;
Intent intent = new Intent(context, sCallingActivityClass);
intent.addFlags(603979776);
return intent;
}
private Intent createResultIntent(String str) {
Intent intent = new Intent();
HashMap<String, String> urlParameters = StringExtensions.getUrlParameters(str);
if (StringExtensions.isNullOrBlank(urlParameters.get("error"))) {
Logger.info(TAG, "It is pointing to redirect. Final url can be processed to get the code or error.");
intent.putExtra(AuthenticationConstants.AuthorizationIntentKey.AUTHORIZATION_FINAL_URL, str);
} else {
Logger.info(TAG, "Sending intent to cancel authentication activity");
intent.putExtra(AuthenticationConstants.Browser.RESPONSE_ERROR_CODE, urlParameters.get("error"));
intent.putExtra(AuthenticationConstants.Browser.RESPONSE_ERROR_SUBCODE, urlParameters.get(AzureActiveDirectoryWebViewClient.ERROR_SUBCODE));
if (StringUtil.isEmpty(urlParameters.get("error_description"))) {
intent.putExtra(AuthenticationConstants.Browser.RESPONSE_ERROR_MESSAGE, urlParameters.get(AzureActiveDirectoryWebViewClient.ERROR_SUBCODE));
} else {
intent.putExtra(AuthenticationConstants.Browser.RESPONSE_ERROR_MESSAGE, urlParameters.get("error_description"));
}
}
return intent;
}
private boolean isDeviceRegisterRedirect(String str) {
try {
URI uri = new URI(str);
if (uri.getScheme().equalsIgnoreCase(AuthenticationConstants.Broker.REDIRECT_PREFIX)) {
return uri.getHost().equalsIgnoreCase(AuthenticationConstants.Broker.DEVICE_REGISTRATION_REDIRECT_URI_HOSTNAME);
}
return false;
} catch (URISyntaxException e) {
Logger.error(TAG, "Uri construction failed", e);
return false;
}
}
@Override
public void extractState(Bundle bundle) {
super.extractState(bundle);
this.mAuthIntent = (Intent) bundle.getParcelable(AuthenticationConstants.AuthorizationIntentKey.AUTH_INTENT);
this.mBrowserFlowStarted = bundle.getBoolean(BROWSER_FLOW_STARTED, false);
}
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
sCallingActivityClass = getActivity().getClass();
}
public void onResume() {
super.onResume();
if (this.mBrowserFlowStarted) {
if (StringUtil.isEmpty(sCustomTabResponseUri)) {
cancelAuthorization(true);
} else {
completeAuthorizationInBrowserFlow(sCustomTabResponseUri);
}
sCustomTabResponseUri = null;
return;
}
this.mBrowserFlowStarted = true;
Intent intent = this.mAuthIntent;
if (intent != null) {
startActivity(intent);
return;
}
Intent intent2 = new Intent();
intent2.putExtra(AuthenticationConstants.Browser.RESPONSE_AUTHENTICATION_EXCEPTION, new ClientException(ErrorStrings.AUTHORIZATION_INTENT_IS_NULL));
sendResult(AuthenticationConstants.UIResponse.BROWSER_CODE_AUTHENTICATION_EXCEPTION, intent2);
finish();
}
public void onSaveInstanceState(Bundle bundle) {
super.onSaveInstanceState(bundle);
bundle.putParcelable(AuthenticationConstants.AuthorizationIntentKey.AUTH_INTENT, this.mAuthIntent);
bundle.putBoolean(BROWSER_FLOW_STARTED, this.mBrowserFlowStarted);
}
}