Skip to content

Commit

Permalink
feat: Sign In With Google and Apple (#84)
Browse files Browse the repository at this point in the history
* feat: get current session information

* feat: create login flow

* feat: login with email and password

* feat: register with email and password

* fix: handle all errors incl deserialization error

* feat: logout & get session on home page init

* feat: show session information

* feat: add design and refactor blocs

* fix: change package and folder name

* fix: change package name

* docs: update README.md

* refactor: delete unused icon

* refactor: remove unused packages

* chore: format code

* refactor: add missing package and delete unused test

* chore: display components dynamically

* chore: clean up and format code

* fix: aal2 navigation

* chore: remove unnecessary code

* feat: sign in/up with google account on iOS

* chore: add ios url scheme and web clientId

* chore: fix typo and rename variables

* chore: separate exception handlings

* fix: prevent null exception

* chore: change package name and add auth packages

* feat: add apple & google sign in

* chore: delete unnecessary exception handling

* feat: add flutter app Ory Network example  (#82)

* feat: get current session information

* feat: create login flow

* feat: login with email and password

* feat: register with email and password

* fix: handle all errors incl deserialization error

* feat: logout & get session on home page init

* feat: show session information

* feat: add design and refactor blocs

* fix: change package and folder name

* fix: change package name

* docs: update README.md

* refactor: delete unused icon

* refactor: remove unused packages

* chore: format code

* refactor: add missing package and delete unused test

* chore: display components dynamically

* chore: clean up and format code

* fix: aal2 navigation

* chore: remove unnecessary code

* chore: fix typo and rename variables

* chore: separate exception handlings

* fix: prevent null exception

* chore: delete unused assets and widgets

* chore: remove misleading widget

* Update README.md

* Update README.md

* chore: add formatting

* chore: add formatting

* chore: change package name

* chore: delete build artifacts

* chore: update gitignore

* chore: add comment about web client id

* chore: add Info.plist snippet to readme

* chore: fix typo

Co-authored-by: Jonas Hungershausen <jonas.hungershausen@gmail.com>

* chore: fix format

* chore: fix format

---------

Co-authored-by: Jonas Hungershausen <jonas.hungershausen@gmail.com>
  • Loading branch information
sashatalalasha and jonas-jonas committed Nov 3, 2023
1 parent 5f53cc5 commit ea68946
Show file tree
Hide file tree
Showing 37 changed files with 2,380 additions and 469 deletions.
46 changes: 46 additions & 0 deletions flutter-ory-network/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,51 @@ migrate_working_dir/
.pub/
/build/

# Android related
**/android/build/
**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java

# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Flutter.podspec
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/Flutter/flutter_export_environment.sh
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*

# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages

# Symbolication related
app.*.symbols

Expand All @@ -43,4 +88,5 @@ app.*.map.json
/android/app/profile
/android/app/release

# Environmental variables
.env
42 changes: 42 additions & 0 deletions flutter-ory-network/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,48 @@ Create .env file with your project url in the root folder of the Flutter app
ORY_BASE_URL=https://{your-project-slug}.projects.oryapis.com
```

### Google Sign In

If you use Google Sign In on Android, add following variable to .env file

```env
WEB_CLIENT_ID={web-client-id}.apps.googleusercontent.com
```

If you use Google Sign In on iOS, add following variable to .env file

```env
IOS_CLIENT_ID={ios-client-id}.apps.googleusercontent.com
```

Additionally, add iOS URL scheme to Info.plist. It can be found in additional
information of your iOS Client ID.

```xml
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<!-- TODO Replace this value with iOS URL scheme from Google Cloud Console -->
<string>IOS_URL_SCHEME</string>
</array>
</dict>
</array>
```

For more information, see
[Google Integration Docs](https://www.ory.sh/docs/kratos/social-signin/google).

### Apple Sign In

To configure Apple Sign In on IOS, see
[Apple Integration Docs](https://www.ory.sh/docs/kratos/social-signin/apple).\
To configure Apple Sign In on Android, see [Social sign-in for native and mobile apps ](https://www.ory.sh/docs/kratos/social-signin/native-apps).

### Run locally

1. Install dependencies from `pubspec.yaml`
Expand Down
6 changes: 3 additions & 3 deletions flutter-ory-network/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
namespace "com.example.ory_network_flutter"
namespace "sh.ory.flutter_ory_network"
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion

Expand All @@ -45,10 +45,10 @@ android {

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.ory_network_flutter"
applicationId "sh.ory.flutter_ory_network"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion 18
minSdkVersion 19
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
41 changes: 35 additions & 6 deletions flutter-ory-network/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:label="Ory Network Flutter"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
android:icon="@mipmap/ic_launcher"
android:usesCleartextTraffic="true">
<activity
android:name=".MainActivity"
android:exported="true"
Expand All @@ -16,12 +18,39 @@
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme" />

<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.linusu.flutter_web_auth.CallbackActivity"
android:exported="true">
<intent-filter android:label="flutter_web_auth">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="ory" />
</intent-filter>
</activity>

<!-- Set up the Sign in with Apple activity, such that it's callable from the browser-redirect -->
<activity
android:name="com.aboutyou.dart_packages.sign_in_with_apple.SignInWithAppleCallback"
android:exported="true">
<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="signinwithapple" />
<data android:path="callback" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0

// Generated file.
//
// If you wish to remove Flutter's multidex support, delete this entire file.
//
// Modifications to this file should be done in a copy under a different name
// as this file may be regenerated.

package io.flutter.app;

import android.app.Application;
import android.content.Context;
import androidx.annotation.CallSuper;
import androidx.multidex.MultiDex;

/**
* Extension of {@link android.app.Application}, adding multidex support.
*/
public class FlutterMultiDexApplication extends Application {
@Override
@CallSuper
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.ory_network_flutter
package sh.ory.flutter_ory_network

import io.flutter.embedding.android.FlutterActivity

Expand Down
Binary file not shown.
Binary file not shown.
44 changes: 44 additions & 0 deletions flutter-ory-network/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,28 +1,72 @@
PODS:
- AppAuth (1.6.2):
- AppAuth/Core (= 1.6.2)
- AppAuth/ExternalUserAgent (= 1.6.2)
- AppAuth/Core (1.6.2)
- AppAuth/ExternalUserAgent (1.6.2):
- AppAuth/Core
- Flutter (1.0.0)
- flutter_secure_storage (6.0.0):
- Flutter
- flutter_web_auth (0.5.0):
- Flutter
- google_sign_in_ios (0.0.1):
- Flutter
- GoogleSignIn (~> 6.2)
- GoogleSignIn (6.2.4):
- AppAuth (~> 1.5)
- GTMAppAuth (~> 1.3)
- GTMSessionFetcher/Core (< 3.0, >= 1.1)
- GTMAppAuth (1.3.1):
- AppAuth/Core (~> 1.6)
- GTMSessionFetcher/Core (< 3.0, >= 1.5)
- GTMSessionFetcher/Core (2.3.0)
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
- sign_in_with_apple (0.0.1):
- Flutter

DEPENDENCIES:
- Flutter (from `Flutter`)
- flutter_secure_storage (from `.symlinks/plugins/flutter_secure_storage/ios`)
- flutter_web_auth (from `.symlinks/plugins/flutter_web_auth/ios`)
- google_sign_in_ios (from `.symlinks/plugins/google_sign_in_ios/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- sign_in_with_apple (from `.symlinks/plugins/sign_in_with_apple/ios`)

SPEC REPOS:
trunk:
- AppAuth
- GoogleSignIn
- GTMAppAuth
- GTMSessionFetcher

EXTERNAL SOURCES:
Flutter:
:path: Flutter
flutter_secure_storage:
:path: ".symlinks/plugins/flutter_secure_storage/ios"
flutter_web_auth:
:path: ".symlinks/plugins/flutter_web_auth/ios"
google_sign_in_ios:
:path: ".symlinks/plugins/google_sign_in_ios/ios"
path_provider_foundation:
:path: ".symlinks/plugins/path_provider_foundation/darwin"
sign_in_with_apple:
:path: ".symlinks/plugins/sign_in_with_apple/ios"

SPEC CHECKSUMS:
AppAuth: 3bb1d1cd9340bd09f5ed189fb00b1cc28e1e8570
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
flutter_secure_storage: 23fc622d89d073675f2eaa109381aefbcf5a49be
flutter_web_auth: c25208760459cec375a3c39f6a8759165ca0fa4d
google_sign_in_ios: 1256ff9d941db546373826966720b0c24804bcdd
GoogleSignIn: 5651ce3a61e56ca864160e79b484cd9ed3f49b7a
GTMAppAuth: 0ff230db599948a9ad7470ca667337803b3fc4dd
GTMSessionFetcher: 3a63d75eecd6aa32c2fc79f578064e1214dfdec2
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
sign_in_with_apple: f3bf75217ea4c2c8b91823f225d70230119b8440

PODFILE CHECKSUM: 70d9d25280d0dd177a5f637cdb0f0b0b12c6a189

Expand Down
15 changes: 11 additions & 4 deletions flutter-ory-network/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
2FC830B17BFE3D0034060C69 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
311C9A0E2AD94FCA0082AC0F /* Runner.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Runner.entitlements; sourceTree = "<group>"; };
331C807B294A618700263BE5 /* RunnerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunnerTests.swift; sourceTree = "<group>"; };
331C8081294A63A400263BE5 /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -130,6 +131,7 @@
97C146F01CF9000F007C117D /* Runner */ = {
isa = PBXGroup;
children = (
311C9A0E2AD94FCA0082AC0F /* Runner.entitlements */,
97C146FA1CF9000F007C117D /* Main.storyboard */,
97C146FD1CF9000F007C117D /* Assets.xcassets */,
97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */,
Expand All @@ -152,7 +154,6 @@
5049002C15409643EB52610C /* Pods-RunnerTests.release.xcconfig */,
572786F99F7DFEE344A536D0 /* Pods-RunnerTests.profile.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
Expand Down Expand Up @@ -467,14 +468,16 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = 44TJKWD29H;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.ory_network_flutter;
PRODUCT_BUNDLE_IDENTIFIER = "sh.ory.flutter-ory-network";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand Down Expand Up @@ -645,14 +648,16 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = 44TJKWD29H;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.ory_network_flutter;
PRODUCT_BUNDLE_IDENTIFIER = "sh.ory.flutter-ory-network";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -667,14 +672,16 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = 44TJKWD29H;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.ory_network_flutter;
PRODUCT_BUNDLE_IDENTIFIER = "sh.ory.flutter-ory-network";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand Down
14 changes: 13 additions & 1 deletion flutter-ory-network/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,25 @@
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>ory_network_flutter</string>
<string>flutter_ory_network</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<!-- TODO Replace this value with iOS URL scheme from Google Cloud Console -->
<string>IOS_URL_SCHEME</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
Expand Down
Loading

0 comments on commit ea68946

Please sign in to comment.