-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NOt Working yet
- Loading branch information
Showing
23 changed files
with
978 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.com.microsoft.adal" | ||
android:versionCode="1" | ||
android:versionName="1.0" > | ||
|
||
<uses-sdk | ||
android:minSdkVersion="8" | ||
android:targetSdkVersion="17" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@drawable/ic_launcher" | ||
android:label="@string/app_name" | ||
android:theme="@style/AppTheme" > | ||
</application> | ||
|
||
</manifest> |
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# To enable ProGuard in your project, edit project.properties | ||
# to define the proguard.config property as described in that file. | ||
# | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in ${sdk.dir}/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the ProGuard | ||
# include property in project.properties. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# This file is automatically generated by Android Tools. | ||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED! | ||
# | ||
# This file must be checked in Version Control Systems. | ||
# | ||
# To customize properties used by the Ant build system edit | ||
# "ant.properties", and override values to adapt the script to your | ||
# project structure. | ||
# | ||
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): | ||
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt | ||
|
||
# Project target. | ||
target=android-17 | ||
android.library=true |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<resources> | ||
|
||
<!-- | ||
Base application theme for API 11+. This theme completely replaces | ||
AppBaseTheme from res/values/styles.xml on API 11+ devices. | ||
--> | ||
<style name="AppBaseTheme" parent="android:Theme.Holo.Light"> | ||
<!-- API 11 theme customizations can go here. --> | ||
</style> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<resources> | ||
|
||
<!-- | ||
Base application theme for API 14+. This theme completely replaces | ||
AppBaseTheme from BOTH res/values/styles.xml and | ||
res/values-v11/styles.xml on API 14+ devices. | ||
--> | ||
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar"> | ||
<!-- API 14 theme customizations can go here. --> | ||
</style> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<resources> | ||
|
||
<string name="app_name">com.microsoft.adal</string> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<resources> | ||
|
||
<!-- | ||
Base application theme, dependent on API level. This theme is replaced | ||
by AppBaseTheme from res/values-vXX/styles.xml on newer devices. | ||
--> | ||
<style name="AppBaseTheme" parent="android:Theme.Light"> | ||
<!-- | ||
Theme customizations available in newer API levels can go in | ||
res/values-vXX/styles.xml, while customizations related to | ||
backward-compatibility can go here. | ||
--> | ||
</style> | ||
|
||
<!-- Application theme. --> | ||
<style name="AppTheme" parent="AppBaseTheme"> | ||
<!-- All customizations that are NOT specific to a particular API-level can go here. --> | ||
</style> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
*/ | ||
package com.microsoft.adal; | ||
|
||
/** | ||
* Callback to use with token request. User implements this callback to use result in their context. | ||
* @author omercan | ||
* | ||
*/ | ||
public interface AuthenticationCallback { | ||
|
||
/** | ||
* This will have the token info. | ||
* @param result | ||
*/ | ||
public void onCompleted(AuthenticationResult result); | ||
|
||
/** | ||
* Send error information. This can be user related error or server error. | ||
* Some cases returns exception and some cases server returns error object such as in the Oauth response. | ||
* This needs to be displayed at the user's screens. | ||
* @param exc | ||
*/ | ||
public void onError(Exception exc); | ||
|
||
/** | ||
* User cancelled the dialog or similar | ||
*/ | ||
public void onCancelled(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
*/ | ||
|
||
package com.microsoft.adal; | ||
|
||
|
||
import java.util.UUID; | ||
|
||
import com.microsoft.protection.authentication.AuthenticationSettings; | ||
|
||
|
||
import android.content.Context; | ||
import android.net.Uri; | ||
|
||
/* | ||
*TODO: error messages define | ||
*TODO: serialization to restore the context onresume inside the client's app so that user does not need to authenticate again | ||
*TODO: Browser flow add | ||
*TODO: | ||
*/ | ||
|
||
/** | ||
* ADAL context to get access token, refresh token | ||
* | ||
* @author omercan | ||
*/ | ||
public class AuthenticationContext { | ||
|
||
/** | ||
* TAG to check messages | ||
*/ | ||
private final static String TAG = "AuthenticationContext"; | ||
|
||
|
||
private String mAuthority; | ||
private String mClientId; | ||
private String mRedirectUri; | ||
private String mLoginHint; | ||
private String mBroadRefreshToken; | ||
|
||
|
||
/** | ||
* Constructs context to use with known authority to get the token | ||
* @param authority | ||
* @param clientId | ||
* @param redirectUri | ||
* @param loginHint | ||
*/ | ||
public AuthenticationContext(String authority, String clientId, String redirectUri, String loginHint) | ||
{ | ||
mAuthority = authority; | ||
mClientId = clientId; | ||
mRedirectUri = redirectUri; | ||
mLoginHint = loginHint; | ||
} | ||
|
||
public void getToken(Context context, String resource, UUID correlationID, | ||
AuthenticationCallback callback) { | ||
|
||
if (callback == null) | ||
throw new IllegalArgumentException("listener is null"); | ||
|
||
if (context == null) | ||
throw new IllegalArgumentException("context is null"); | ||
|
||
// Check authority url | ||
ExtractUrl(); | ||
|
||
// If user has enabled validation, it will call the discovery service to verify the instance | ||
ValidateAuthority(); | ||
|
||
|
||
|
||
} | ||
|
||
private void ValidateAuthority() | ||
{ | ||
if(getSettings().getValidateAuthority()) | ||
{ | ||
if(!getSettings().getDiscovery().IsValidAuthority(mAuthority)) | ||
{ | ||
throw new IllegalArgumentException("Authority is not valid"); | ||
} | ||
} | ||
} | ||
|
||
private void ExtractUrl() | ||
{ | ||
// Authorization server URL is like "https://login.windows.net/somewhere.onmicrosoft.com" | ||
// - must not be empty | ||
// - must be absolute | ||
// - must not have query or fragment | ||
// - must be https | ||
if (mAuthority == null || mAuthority.isEmpty()) | ||
throw new IllegalArgumentException("authorizationServer"); | ||
|
||
|
||
Uri uri = Uri.parse(mAuthority); | ||
|
||
if (!uri.isAbsolute()) { | ||
throw new IllegalArgumentException("authorizationServer"); | ||
} | ||
if (!uri.getScheme().equalsIgnoreCase("https")) { | ||
throw new IllegalArgumentException("authorizationServer"); | ||
} | ||
if (uri.getFragment() != null || uri.getQuery() != null) { | ||
throw new IllegalArgumentException("authorizationServer has query or fragments"); | ||
} | ||
|
||
// Normalize authority url to remove extra url parts | ||
int thirdSlash = mAuthority.indexOf("/", 8); // exclude starting https:// or http:// | ||
if (thirdSlash >= 0) | ||
{ | ||
if (thirdSlash != (mAuthority.length() - 1)) | ||
{ | ||
// Extract url | ||
int fourthSlash = mAuthority.indexOf("/", thirdSlash + 1); | ||
if (fourthSlash > thirdSlash + 1) | ||
{ | ||
mAuthority.substring(0, fourthSlash); | ||
} | ||
} | ||
} | ||
|
||
throw new IllegalArgumentException("Authority url"); | ||
} | ||
|
||
public static AuthenticationSettings getSettings() { | ||
return AuthenticationSettings.getInstance(); | ||
} | ||
|
||
public void getTokenNoUI(TokenRequest request, AuthenticationCallback callback) | ||
{ | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package com.microsoft.adal; | ||
import java.io.Serializable; | ||
import java.util.Date; | ||
|
||
/** | ||
* ---------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* ---------------------------------------------------------------- | ||
*/ | ||
|
||
/** | ||
* Serializable properties | ||
* Mark temp properties as Transient if you dont want to keep them in serialization | ||
* @author omercan | ||
* | ||
*/ | ||
public class AuthenticationResult implements Serializable { | ||
|
||
private String mAccessToken; | ||
public String getAccessToken() { | ||
return mAccessToken; | ||
} | ||
public void setmccessToken(String mAccessToken) { | ||
this.mAccessToken = mAccessToken; | ||
} | ||
public String getCode() { | ||
return mCode; | ||
} | ||
public void setCode(String mCode) { | ||
this.mCode = mCode; | ||
} | ||
public String getAuthorizationEndpoint() { | ||
return mAuthorizationEndpoint; | ||
} | ||
public void setAuthorizationEndpoint(String mAuthorizationEndpoint) { | ||
this.mAuthorizationEndpoint = mAuthorizationEndpoint; | ||
} | ||
public String getTokenEndpoint() { | ||
return mTokenEndpoint; | ||
} | ||
public void setTokenEndpoint(String mTokenEndpoint) { | ||
this.mTokenEndpoint = mTokenEndpoint; | ||
} | ||
public String getRedirectUri() { | ||
return mRedirectUri; | ||
} | ||
public void setRedirectUri(String mRedirectUri) { | ||
this.mRedirectUri = mRedirectUri; | ||
} | ||
public String getRefreshToken() { | ||
return mRefreshToken; | ||
} | ||
public void setRefreshToken(String mRefreshToken) { | ||
this.mRefreshToken = mRefreshToken; | ||
} | ||
public String getResource() { | ||
return mResource; | ||
} | ||
public void setResource(String mResource) { | ||
this.mResource = mResource; | ||
} | ||
public String getScope() { | ||
return mScope; | ||
} | ||
public void setScope(String mScope) { | ||
this.mScope = mScope; | ||
} | ||
public String getClientId() { | ||
return mClientId; | ||
} | ||
public void setClientId(String mClientId) { | ||
this.mClientId = mClientId; | ||
} | ||
public String getAccessTokenType() { | ||
return mAccessTokenType; | ||
} | ||
public void setAccessTokenType(String mAccessTokenType) { | ||
this.mAccessTokenType = mAccessTokenType; | ||
} | ||
public Date getExpires() { | ||
return mExpires; | ||
} | ||
public void setExpires(Date mExpires) { | ||
this.mExpires = mExpires; | ||
} | ||
public String getResponseType() { | ||
return mResponseType; | ||
} | ||
public void setResponseType(String mResponseType) { | ||
this.mResponseType = mResponseType; | ||
} | ||
private String mCode; | ||
private String mAuthorizationEndpoint; | ||
private String mTokenEndpoint; | ||
private String mRedirectUri; | ||
private String mRefreshToken; | ||
private String mResource; | ||
private String mScope; | ||
private String mClientId; | ||
private String mAccessTokenType; | ||
private Date mExpires; | ||
private String mResponseType; | ||
} | ||
|
||
|
Oops, something went wrong.