-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bindings to native APIs for authentication via ASWebAuthenticationSession and Custom Tabs
- Loading branch information
Showing
168 changed files
with
86,939 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,45 @@ | ||
name: native_auth_flutter | ||
on: | ||
pull_request: | ||
paths: | ||
- ".github/workflows/native_auth_flutter.yaml" | ||
- "packages/native/auth/native_auth_flutter/**" | ||
|
||
# Prevent duplicate runs due to Graphite | ||
# https://graphite.dev/docs/troubleshooting#why-are-my-actions-running-twice | ||
concurrency: | ||
group: ${{ github.repository }}-${{ github.workflow }}-${{ github.ref }}-${{ github.ref == 'refs/heads/main' && github.sha || ''}} | ||
cancel-in-progress: true | ||
|
||
defaults: | ||
run: | ||
working-directory: packages/native/auth/native_auth_flutter | ||
|
||
jobs: | ||
build: | ||
runs-on: macos-latest-xlarge | ||
timeout-minutes: 25 | ||
steps: | ||
- name: Git Checkout | ||
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # 4.1.6 | ||
- name: Setup Flutter | ||
uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1 # 2.16.0 | ||
with: | ||
channel: stable | ||
cache: true | ||
- name: Get Packages | ||
run: flutter pub get | ||
- name: Analyze | ||
run: dart analyze --fatal-infos --fatal-warnings | ||
- name: Format | ||
run: dart format --set-exit-if-changed . | ||
# - name: Test | ||
# run: dart test | ||
# - name: Test (Example) | ||
# run: dart test | ||
- name: Build Example (iOS) | ||
run: flutter build ios --no-codesign | ||
working-directory: packages/native/auth/native_auth_flutter/example | ||
- name: Build Example (Web) | ||
run: flutter build web | ||
working-directory: packages/native/auth/native_auth_flutter/example |
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,29 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
migrate_working_dir/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. | ||
/pubspec.lock | ||
**/doc/api/ | ||
.dart_tool/ | ||
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,36 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: "80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819" | ||
channel: "stable" | ||
|
||
project_type: plugin_ffi | ||
|
||
# Tracks metadata for the flutter migrate command | ||
migration: | ||
platforms: | ||
- platform: root | ||
create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 | ||
base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 | ||
- platform: android | ||
create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 | ||
base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 | ||
- platform: ios | ||
create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 | ||
base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 | ||
- platform: macos | ||
create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 | ||
base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819 | ||
|
||
# User provided section | ||
|
||
# List of Local paths (relative to this file) that should be | ||
# ignored by the migrate tool. | ||
# | ||
# Files that are not part of the templates will be ignored by default. | ||
unmanaged_files: | ||
- 'lib/main.dart' | ||
- 'ios/Runner.xcodeproj/project.pbxproj' |
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 @@ | ||
## 0.0.1 | ||
|
||
* TODO: Describe initial release. |
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 @@ | ||
TODO: Add your license here. |
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,92 @@ | ||
# native_auth_flutter | ||
|
||
A new Flutter FFI plugin project. | ||
|
||
## Getting Started | ||
|
||
This project is a starting point for a Flutter | ||
[FFI plugin](https://flutter.dev/to/ffi-package), | ||
a specialized package that includes native code directly invoked with Dart FFI. | ||
|
||
## Project structure | ||
|
||
This template uses the following structure: | ||
|
||
* `src`: Contains the native source code, and a CmakeFile.txt file for building | ||
that source code into a dynamic library. | ||
|
||
* `lib`: Contains the Dart code that defines the API of the plugin, and which | ||
calls into the native code using `dart:ffi`. | ||
|
||
* platform folders (`android`, `ios`, `windows`, etc.): Contains the build files | ||
for building and bundling the native code library with the platform application. | ||
|
||
## Building and bundling native code | ||
|
||
The `pubspec.yaml` specifies FFI plugins as follows: | ||
|
||
```yaml | ||
plugin: | ||
platforms: | ||
some_platform: | ||
ffiPlugin: true | ||
``` | ||
This configuration invokes the native build for the various target platforms | ||
and bundles the binaries in Flutter applications using these FFI plugins. | ||
This can be combined with dartPluginClass, such as when FFI is used for the | ||
implementation of one platform in a federated plugin: | ||
```yaml | ||
plugin: | ||
implements: some_other_plugin | ||
platforms: | ||
some_platform: | ||
dartPluginClass: SomeClass | ||
ffiPlugin: true | ||
``` | ||
A plugin can have both FFI and method channels: | ||
```yaml | ||
plugin: | ||
platforms: | ||
some_platform: | ||
pluginClass: SomeName | ||
ffiPlugin: true | ||
``` | ||
The native build systems that are invoked by FFI (and method channel) plugins are: | ||
* For Android: Gradle, which invokes the Android NDK for native builds. | ||
* See the documentation in android/build.gradle. | ||
* For iOS and MacOS: Xcode, via CocoaPods. | ||
* See the documentation in ios/native_auth_flutter.podspec. | ||
* See the documentation in macos/native_auth_flutter.podspec. | ||
* For Linux and Windows: CMake. | ||
* See the documentation in linux/CMakeLists.txt. | ||
* See the documentation in windows/CMakeLists.txt. | ||
## Binding to native code | ||
To use the native code, bindings in Dart are needed. | ||
To avoid writing these by hand, they are generated from the header file | ||
(`src/native_auth_flutter.h`) by `package:ffigen`. | ||
Regenerate the bindings by running `dart run ffigen --config ffigen.yaml`. | ||
|
||
## Invoking native code | ||
|
||
Very short-running native functions can be directly invoked from any isolate. | ||
For example, see `sum` in `lib/native_auth_flutter.dart`. | ||
|
||
Longer-running functions should be invoked on a helper isolate to avoid | ||
dropping frames in Flutter applications. | ||
For example, see `sumAsync` in `lib/native_auth_flutter.dart`. | ||
|
||
## Flutter help | ||
|
||
For help getting started with Flutter, view our | ||
[online documentation](https://docs.flutter.dev), which offers tutorials, | ||
samples, guidance on mobile development, and a full API reference. | ||
|
5 changes: 5 additions & 0 deletions
5
packages/native/auth/native_auth_flutter/analysis_options.yaml
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 @@ | ||
include: package:flutter_lints/flutter.yaml | ||
|
||
analyzer: | ||
exclude: | ||
- '**/*.ffi.dart' |
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,9 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.cxx |
69 changes: 69 additions & 0 deletions
69
packages/native/auth/native_auth_flutter/android/build.gradle
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,69 @@ | ||
group = "dev.celest.native_auth" | ||
version = "1.0" | ||
|
||
buildscript { | ||
// Matches package:jni | ||
// https://github.com/dart-lang/native/blob/main/pkgs/jni/android/build.gradle#L7 | ||
ext.kotlin_version = '1.6.10' | ||
repositories { | ||
google() | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
classpath "com.android.tools.build:gradle:7.4.2" | ||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | ||
} | ||
} | ||
|
||
rootProject.allprojects { | ||
repositories { | ||
google() | ||
mavenCentral() | ||
} | ||
} | ||
|
||
apply plugin: "com.android.library" | ||
apply plugin: 'kotlin-android' | ||
|
||
android { | ||
if (project.android.hasProperty("namespace")) { | ||
namespace = "dev.celest.native_auth" | ||
} | ||
|
||
compileSdk 34 | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
|
||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
|
||
sourceSets { | ||
main.java.srcDirs += 'src/main/kotlin' | ||
} | ||
|
||
defaultConfig { | ||
minSdkVersion 21 | ||
consumerProguardFiles 'consumer-rules.pro' | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
} | ||
} | ||
|
||
testOptions { | ||
unitTests { | ||
includeAndroidResources = true | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation "androidx.browser:browser:1.8.0" | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/native/auth/native_auth_flutter/android/consumer-rules.pro
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 @@ | ||
-keep class dev.celest.native_auth.** { *; } | ||
-if class androidx.credentials.CredentialManager | ||
-keep class androidx.credentials.playservices.** { | ||
*; | ||
} |
1 change: 1 addition & 0 deletions
1
packages/native/auth/native_auth_flutter/android/settings.gradle
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 @@ | ||
rootProject.name = 'native_auth_flutter' |
30 changes: 30 additions & 0 deletions
30
packages/native/auth/native_auth_flutter/android/src/main/AndroidManifest.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,30 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="dev.celest.native_auth"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application> | ||
<activity | ||
android:name=".NativeAuthRedirectManagerActivity" | ||
android:exported="false" | ||
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" | ||
android:launchMode="singleTask" /> | ||
<activity | ||
android:name=".NativeAuthRedirectReceiverActivity" | ||
android:exported="true" | ||
android:theme="@android:style/Theme.NoDisplay"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.VIEW" /> | ||
<category android:name="android.intent.category.DEFAULT" /> | ||
<category android:name="android.intent.category.BROWSABLE" /> | ||
<data android:scheme="${nativeAuthRedirectScheme}" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
<queries> | ||
<intent> | ||
<action android:name="android.support.customtabs.action.CustomTabsService" /> | ||
</intent> | ||
</queries> | ||
</manifest> |
Oops, something went wrong.