Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Platform Sign In #1366

Merged
merged 2 commits into from
Aug 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Fuse.Auth
- Introducing Fuse.Auth, the easiest way to perform user authentication using biometric sensor that reside on the device such as fingerprint or FaceID
- Introducing Platform SignIn. a Sign In mechanism that use `Sign In With Apple` on iOS and `Google SignIn` on Android. There is two API added, `PlatformSignIn` as trigger action and `FuseJS/Auth` as javascript module.

# 1.14

Expand Down
7 changes: 6 additions & 1 deletion Source/Fuse.Auth/Fuse.Auth.unoproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@
"../Fuse/Fuse.unoproj"
],
"Includes": [
"*"
"*",
"iOS/SignInHelper.h:ObjCHeader:iOS",
"iOS/SignInHelper.mm:ObjCSource:iOS"
],
"iOS": {
"PList": {
"NSFaceIDUsageDescription": "Require access to FaceID for authenticating"
},
"SystemCapabilities": {
"SignInWithApple": true
}
}
}

129 changes: 129 additions & 0 deletions Source/Fuse.Auth/SignInModule.uno
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
using Uno;
using Uno.UX;
using Fuse;
using Fuse.Scripting;
using Uno.Threading;

namespace Fuse
{
[UXGlobalModule]
/**
Javascript Module for taking Platform SignIn. Platform SignIn is a SignIn mechanism that use `Sign In With Apple` on iOS and `Google SignIn` on Android.

Platform SignIn is only available on the mobile target platform (iOS and Android).

You need to add a reference to `"Fuse.Auth"` in your project file to use this feature.

> For more information on what are the pre-request when implementing `Sign In With Apple` or `Google Sign In`, you can check the documentation on the apple developer website or android developer website
> for iOS add "SystemCapabilities": { "SignInWithApple":true } in the unoproj file.

## Example

The following example shows how to use it:

```XML
<App>
<JavaScript>
var Auth = require('useJS/Auth');

function doSignIn() {
Auth.signIn().then(function(result) {
// result is json object containing these properties :
// email -> user email that has been sign in / sign up
// firstName -> User firstname
// lastName -> User Lastname
// userId -> User uniqe Id
}, function (ex) {
// failed login
})
}
Auth.hasSignedIn().then(function (result) {
if (result) {
// user has already sign in
}
})

module.exports = {
doSignIn
}

</JavaScript>
<Button Text="Sign In">
<Clicked>
<Callback Handler="{doSignIn}" />
</Clicked>
</Button>
</App
```

> When the callback handler is fired for the first time and the result object of `status` property is true, save those logged user information immediately to the server especially on iOS,
> because as stated in the documentation on the apple website, the Sign In With Apple will only send userId informataion the next time user do the authentication again

*/
public class SignInModule : NativeModule
{
static readonly SignInModule _instance;

public SignInModule()
{
if (_instance != null) return;

_instance = this;
Resource.SetGlobalKey(_instance, "FuseJS/Auth");
AddMember(new NativePromise<bool, bool>("hasSignedIn", HasSignedIn));
AddMember(new NativePromise<LoginInformation, Scripting.Object>("signIn", SignIn, Converter));
}

static Future<bool> HasSignedIn(object[] args)
{
var p = new Promise<bool>();
if defined (iOS)
SignInWithApple.HasSignedIn(p);
if defined (Android)
SignInWithGoogle.HasSignedIn(p);
return p;
}

static Future<LoginInformation> SignIn(object[] args)
{
var p = new Promise<LoginInformation>();
if defined (iOS)
SignInWithApple.SignIn(p);
if defined (Android)
SignInWithGoogle.SignIn(p);
return p;
}

static Scripting.Object Converter(Context context, LoginInformation loginInfo)
{
var wrapperObject = context.NewObject();
wrapperObject["userId"] = loginInfo.CurrentIdentifier;
wrapperObject["firstName"] = loginInfo.FamilyName;
wrapperObject["lastName"] = loginInfo.GivenName;
wrapperObject["email"] = loginInfo.Email;
wrapperObject["user"] = loginInfo.User;
wrapperObject["password"] = loginInfo.Password;
return wrapperObject;
}
}

internal class LoginInformation
{
public string CurrentIdentifier;
public string FamilyName;
public string GivenName;
public string Email;
public string User;
public string Password;

public LoginInformation( string currIdentifier, string familyName, string givenName, string email, string user, string password)
{
CurrentIdentifier = currIdentifier;
FamilyName = familyName;
GivenName = givenName;
Email = email;
User = user;
Password = password;
}
}
}
Loading