Skip to content

Commit

Permalink
Merge pull request #245 from AzureAD/dev
Browse files Browse the repository at this point in the history
release to master
  • Loading branch information
omercs committed Aug 22, 2014
2 parents df44f44 + 81cdaa3 commit 1dc3ccb
Show file tree
Hide file tree
Showing 25 changed files with 371 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: android
jdk: oraclejdk7
android:
components:
- build-tools-19.0.2
- build-tools-19.1.0
env:
matrix:
- ANDROID_SDKS=android-18 ANDROID_TARGET=android-18
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<properties>
<scm.branch>master</scm.branch>
<maven.version>3.1.1</maven.version>
<adal.version>1.0.0</adal.version>
<adal.version>1.0.1</adal.version>
<android.platform.maven.plugin>18</android.platform.maven.plugin>
<android.version>[4.1.1.4,)</android.version>
<android.support.version>[18,)</android.support.version>
Expand Down
13 changes: 13 additions & 0 deletions samples/hello/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,17 @@
android:onClick="onClickAcquireTokenSilent"
android:text="Get Token Silent" />

<EditText
android:id="@+id/editTextUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button4"
android:layout_alignRight="@+id/button4"
android:layout_below="@+id/button4"
android:ems="10"
android:hint="@string/login_hint" >

<requestFocus />
</EditText>

</RelativeLayout>
1 change: 1 addition & 0 deletions samples/hello/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
<string name="broker_authentication_request_is_invalid">Authetication request is invalid</string>
<string name="broker_processing">Broker is processing</string>
<string name="login_title">Hello Login</string>
<string name="login_hint">[email protected]</string>

</resources>
2 changes: 2 additions & 0 deletions samples/hello/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

Expand Down
2 changes: 2 additions & 0 deletions samples/hello/src/com/microsoft/aad/adal/hello/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ public class Constants {
public static final String KEY_NAME_ASK_BROKER_INSTALL = "test.settings.ask.broker";

public static final String KEY_NAME_CHECK_BROKER = "test.settings.check.broker";

public static final String LOGIN_HINT = "[email protected]";
}
27 changes: 13 additions & 14 deletions samples/hello/src/com/microsoft/aad/adal/hello/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
Expand All @@ -34,19 +32,16 @@
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.Signature;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

Expand All @@ -72,6 +67,8 @@ public class MainActivity extends Activity {

TextView textView1;

EditText mEditText;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -83,14 +80,20 @@ protected void onCreate(Bundle savedInstanceState) {
clearSessionCookie();
try {
// Provide key info for Encryption
Utils.setupKeyForSample();
if (Build.VERSION.SDK_INT < 18) {
Utils.setupKeyForSample();
}

// init authentication Context
mAuthContext = new AuthenticationContext(MainActivity.this, Constants.AUTHORITY_URL,
false);
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Encryption failed", Toast.LENGTH_SHORT).show();
}

mEditText = (EditText)findViewById(R.id.editTextUsername);
mEditText.setText("");

Toast.makeText(getApplicationContext(), TAG + "done", Toast.LENGTH_SHORT).show();
}

Expand Down Expand Up @@ -186,6 +189,7 @@ public void onSuccess(AuthenticationResult result) {
if (mResult.getUserInfo() != null) {
Log.v(TAG, "User info userid:" + result.getUserInfo().getUserId()
+ " displayableId:" + result.getUserInfo().getDisplayableId());
mEditText.setText(result.getUserInfo().getDisplayableId());
Toast.makeText(getApplicationContext(),
"User:" + mResult.getUserInfo().getDisplayableId(), Toast.LENGTH_SHORT)
.show();
Expand Down Expand Up @@ -286,12 +290,7 @@ private String getUserId() {
}

private String getUserLoginHint() {
if (mResult != null && mResult.getUserInfo() != null
&& mResult.getUserInfo().getDisplayableId() != null) {
return mResult.getUserInfo().getDisplayableId();
}

return null;
return mEditText.getText().toString();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.aad</groupId>
<artifactId>adal</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<packaging>aar</packaging>
<name>adal</name>
<properties>
<scm.branch>master</scm.branch>
<maven.version>3.1.1</maven.version>
<adal.version>1.0.0</adal.version>
<adal.version>1.0.1</adal.version>
<android.platform.maven.plugin>18</android.platform.maven.plugin>
<android.version>[4.1.1.4,)</android.version>
<android.support.version>[18,)</android.support.version>
Expand Down
2 changes: 1 addition & 1 deletion src/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="button_cancel">Cancel</string>
<string name="app_loading">Loading...</string>
<string name="app_loading"></string>
<string name="title_activity_token">TokenActivity</string>
<string name="title_activity_authentication">Authentication </string>
<string name="title_confirmation_activity_authentication">Confirm</string>
Expand Down
66 changes: 52 additions & 14 deletions src/src/com/microsoft/aad/adal/AuthenticationActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
import java.security.DigestException;
import java.security.InvalidAlgorithmParameterException;
Expand Down Expand Up @@ -48,6 +49,7 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.net.Uri;
import android.net.http.SslError;
import android.os.AsyncTask;
import android.os.Bundle;
Expand Down Expand Up @@ -260,21 +262,44 @@ protected void onCreate(Bundle savedInstanceState) {
final String postUrl = mStartUrl;
Logger.v(TAG, "OnCreate startUrl:" + mStartUrl + " calling package:" + mCallingPackage
+ " loginHint:" + mAuthRequest.getLoginHint());
mWebView.post(new Runnable() {
@Override
public void run() {
// load blank first
mWebView.loadUrl("about:blank");
mWebView.loadUrl(postUrl);
}
});

if (savedInstanceState == null) {
mWebView.post(new Runnable() {
@Override
public void run() {
// load blank first to avoid error for not loading webview
mWebView.loadUrl("about:blank");
mWebView.loadUrl(postUrl);
}
});
} else {
Logger.d(TAG, "Reuse webview");
}
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);

// Save the state of the WebView
mWebView.saveState(outState);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);

// Restore the state of the WebView
mWebView.restoreState(savedInstanceState);
}

private void setupWebView() {

// Spinner dialog to show some message while it is loading
mSpinner = new ProgressDialog(this);
mSpinner.requestWindowFeature(Window.FEATURE_NO_TITLE);
mSpinner.setMessage(this.getText(this.getResources().getIdentifier("app_loading", "string",
this.getPackageName())));

// Create the Web View to show the page
mWebView = (WebView)findViewById(this.getResources().getIdentifier("webView1", "id",
Expand Down Expand Up @@ -587,8 +612,10 @@ public void run() {
return true;
} else {
Logger.v(TAG, "It is a broker request");
displaySpinnerWithMessage(AuthenticationActivity.this.getResources().getString(
R.string.broker_processing));
displaySpinnerWithMessage(AuthenticationActivity.this
.getText(AuthenticationActivity.this.getResources().getIdentifier(
"broker_processing", "string", getPackageName())));

view.stopLoading();

// do async task and show spinner while exchanging code for
Expand All @@ -597,6 +624,11 @@ public void run() {
.execute(url);
return true;
}
} else if (url.startsWith(AuthenticationConstants.Broker.BROWSER_EXT_PREFIX)) {
Logger.v(TAG, "It is an external website request");
openLinkInBrowser(url);
view.stopLoading();
return true;
}

if (isBrokerRequest(getIntent())
Expand Down Expand Up @@ -664,10 +696,17 @@ public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
displaySpinner(true);
}

private void openLinkInBrowser(String url) {
String link = url
.replace(AuthenticationConstants.Broker.BROWSER_EXT_PREFIX, "https://");
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
startActivity(intent);
}
}

/**
* handle spinner display
* handle spinner display.
*
* @param show
*/
Expand All @@ -683,11 +722,10 @@ private void displaySpinner(boolean show) {
}
}

private void displaySpinnerWithMessage(String msg) {
private void displaySpinnerWithMessage(CharSequence charSequence) {
if (!AuthenticationActivity.this.isFinishing() && mSpinner != null) {
mSpinner.show();
mSpinner.setTitle("Processing ");
mSpinner.setMessage(msg);
mSpinner.setMessage(charSequence);
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/src/com/microsoft/aad/adal/AuthenticationConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ public static final class Broker {

public static final String ACCOUNT_USERINFO_TENANTID = "account.userinfo.tenantid";

public static final String ADAL_VERSION_KEY = "adal.version.key";

public static final String ACCOUNT_UID_CACHES = "account.uid.caches";

public static final String USERDATA_PREFIX = "userdata.prefix";
Expand All @@ -271,7 +273,7 @@ public static final class Broker {
/**
* Certificate authorities are passed with delimiter.
*/
public static final String CHALLANGE_REQUEST_CERT_AUTH_DELIMETER = ",";
public static final String CHALLANGE_REQUEST_CERT_AUTH_DELIMETER = ";";

/**
* Apk packagename that will install AD-Authenticator. It is used to
Expand All @@ -294,6 +296,8 @@ public static final class Broker {
public static final String REDIRECT_PREFIX = "msauth";

public static final Object REDIRECT_DELIMETER_ENCODED = "%2C";

public static final String BROWSER_EXT_PREFIX = "browser://";
}

public static final String ADAL_PACKAGE_NAME = "com.microsoft.aad.adal";
Expand Down
6 changes: 3 additions & 3 deletions src/src/com/microsoft/aad/adal/AuthenticationContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ private AuthenticationResult acquireTokenAfterValidation(CallbackHandler callbac
if (mBrokerProxy.canSwitchToBroker()) {
Logger.v(TAG, "It switched to broker for context: " + mContext.getPackageName());
AuthenticationResult result = null;

request.setVersion(getVersionName());
// Don't send background request, if prompt flag is always or
// refresh_session
if (!promptUser(request.getPrompt())) {
Expand Down Expand Up @@ -1324,7 +1324,7 @@ private void setItemToCache(final AuthenticationRequest request, AuthenticationR
&& !StringExtensions.IsNullOrBlank(result.getUserInfo().getDisplayableId())) {
Logger.v(TAG, "Updating cache for username:"
+ result.getUserInfo().getDisplayableId() + getCorrelationLogInfo());
userKey = result.getUserInfo().getDisplayableId();
setItemToCacheForUser(request, result, result.getUserInfo().getDisplayableId());
}
} else if (StringExtensions.IsNullOrBlank(userKey)) {
userKey = request.getLoginHint();
Expand Down Expand Up @@ -1762,6 +1762,6 @@ public static String getVersionName() {
// Package manager does not report for ADAL
// AndroidManifest files are not merged, so it is returning hard coded
// value
return "1.0.0";
return "1.0.1";
}
}
10 changes: 10 additions & 0 deletions src/src/com/microsoft/aad/adal/AuthenticationRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class AuthenticationRequest implements Serializable {

private boolean mSilent = false;

private String mVersion = null;

public AuthenticationRequest() {

}
Expand Down Expand Up @@ -207,4 +209,12 @@ public boolean isSilent() {
public void setSilent(boolean silent) {
this.mSilent = silent;
}

public String getVersion() {
return mVersion;
}

public void setVersion(String version) {
this.mVersion = version;
}
}
Loading

0 comments on commit 1dc3ccb

Please sign in to comment.