-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unity3D Android/iOS sample app that uses IdentityModel.OidcClient2 fo…
…r authentication.
- Loading branch information
1 parent
ff38f0a
commit 7f8b388
Showing
80 changed files
with
3,987 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,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 |
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 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/caches/build_file_checksums.ser | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,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 |
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 @@ | ||
/build |
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,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 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,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 |
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,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> |
50 changes: 50 additions & 0 deletions
50
AndroidUnityPlugin/app/src/main/java/org/identitymodel/unityclient/AuthRedirectActivity.java
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,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; | ||
} | ||
} | ||
} |
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
</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,3 @@ | ||
<resources> | ||
<string name="app_name">AndroidUnityPlugin</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,3 @@ | ||
<resources> | ||
|
||
</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,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 | ||
} |
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 @@ | ||
# 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.
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,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 |
Oops, something went wrong.