Skip to content

Commit

Permalink
Unity3D Android/iOS sample app that uses IdentityModel.OidcClient2 fo…
Browse files Browse the repository at this point in the history
…r authentication.
  • Loading branch information
peterhorsley committed Jun 22, 2018
1 parent ff38f0a commit 7f8b388
Show file tree
Hide file tree
Showing 80 changed files with 3,987 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Oo]utput/
/[Bb]uilds/
/Assets/AssetStoreTools*
/.vs/

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
.vscode

# Unity3D generated meta files
*.pidb.meta

# Unity3D Generated File On Crash Reports
sysinfo.txt

# Builds
*.apk
*.unitypackage
buildlog.txt

#MacOS temp files
.DS_Store

# Google Play Services Resolver
ProjectSettings/AndroidResolverDependencies.xml
11 changes: 11 additions & 0 deletions AndroidUnityPlugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*.iml
.gradle
/local.properties
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/caches/build_file_checksums.ser
.DS_Store
/build
/captures
.externalNativeBuild
29 changes: 29 additions & 0 deletions AndroidUnityPlugin/.idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions AndroidUnityPlugin/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions AndroidUnityPlugin/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions AndroidUnityPlugin/.idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions AndroidUnityPlugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# AndroidUnityPlugin

What is this project?
- This is a minimal Android library project that provides auth redirect handling back to the Unity Android app.

How does it work?
- The AndroidManifest.xml file stored in Assets/Plugins/Android folder includes the definition of the AuthRedirectActivity
and adds an intent filter for the custom scheme used for the redirect. When an intent is launched on Android with this custom
scheme, the AuthRedirectActivity is instantiated and the value of the uri is sent in a message back to a Unity game object.
Then, the main activity (UnityPlayerActivity) is launched and the AuthRedirectActivity is finished.

How is it built?
- Run (double-click) the exportJar Gradle task, this will produce a new AndroidUnityPlugin.jar
file and copy it into the the Assets/Plugins/Android folder in the Unity project.
This jar file and associated source code changes should be committed to your repo.

Anything else?
- If a new version of Unity is released, it may be necessary to copy the classes.jar file from:
C:\Program Files\Unity 2018.1\Editor\Data\PlaybackEngines\AndroidPlayer\Variations\mono\Release\Classes\classes.jar
to:
\AndroidUnityPlugin\app\libs\classes.jar

Relevent links for how this project was constructed are:
- https://blog.getsocial.im/android-unity-app-and-the-intent-issue/
- http://addcomponent.com/android-native-plugin-unity/
- https://www.theseus.fi/bitstream/handle/10024/139801/kuitunen_jeremias.pdf?sequence=1&isAllowed=y
1 change: 1 addition & 0 deletions AndroidUnityPlugin/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
40 changes: 40 additions & 0 deletions AndroidUnityPlugin/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 26
defaultConfig {
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '27.0.3'
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

task exportJar(type: Copy) {
from('build/intermediates/bundles/release/classes.jar')
into('../../Assets/Plugins/Android')
include('classes.jar')
rename('classes.jar', 'AndroidUnityPlugin.jar')
}

task deleteOldJar(type: Delete) {
delete 'release/AndroidUnityPlugin.jar'
}


exportJar.dependsOn(deleteOldJar, build)
Binary file added AndroidUnityPlugin/app/libs/classes.jar
Binary file not shown.
21 changes: 21 additions & 0 deletions AndroidUnityPlugin/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# 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 *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
8 changes: 8 additions & 0 deletions AndroidUnityPlugin/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.identitymodel.unityclient">

<application
android:allowBackup="true"
android:label="@string/app_name"
/>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.identitymodel.unityclient;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;

import com.unity3d.player.UnityPlayer;

// An activity to handle auth redirects on Android.
// The value query string is sent to the OnAuthReply method on the
// SignInBehavior script on the SignInCanvas object in the Unity scene.
public class AuthRedirectActivity extends Activity {

private static String TAG = "AuthRedirectActivity";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
Log.v(TAG, "onCreate");
Uri dataUri = getIntent().getData();
if (dataUri != null) {
Log.v(TAG, String.format("Data uri: [%s]", dataUri.toString()));
String query = dataUri.getQuery();
if (query != null) {
Log.v(TAG, String.format("Data uri query: [%s]", query));
UnityPlayer.UnitySendMessage("SignInCanvas", "OnAuthReply", query);
}
}

Log.v(TAG, "Returning to main activity");
Intent newIntent = new Intent(this, getMainActivityClass());
this.startActivity(newIntent);
finish();
}

private Class<?> getMainActivityClass() {
String packageName = this.getPackageName();
Intent launchIntent = this.getPackageManager().getLaunchIntentForPackage(packageName);
try {
return Class.forName(launchIntent.getComponent().getClassName());
} catch (Exception e) {
Log.e(TAG, "Unable to find Main Activity Class");
return null;
}
}
}
4 changes: 4 additions & 0 deletions AndroidUnityPlugin/app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

</resources>
3 changes: 3 additions & 0 deletions AndroidUnityPlugin/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">AndroidUnityPlugin</string>
</resources>
3 changes: 3 additions & 0 deletions AndroidUnityPlugin/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>

</resources>
27 changes: 27 additions & 0 deletions AndroidUnityPlugin/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'


// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
google()
jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
17 changes: 17 additions & 0 deletions AndroidUnityPlugin/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
Binary file not shown.
6 changes: 6 additions & 0 deletions AndroidUnityPlugin/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Tue May 08 14:19:40 AEST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
Loading

0 comments on commit 7f8b388

Please sign in to comment.