示例#1
0
        void RegisterEvents()
        {
            ViewModel.PropertyChanged += async(sender, e) =>
            {
                switch (e.PropertyName)
                {
                case "MoveToTwo":
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        ViewModel.EmailAddress = string.Empty;
                        mainInnerStack?.Children.RemoveAt(1);
                        mainInnerStack?.Children.Add(AccountDetails.GenerateAccountDetails(titleBar, ViewModel));
                    });
                    break;

                case "MoveToThree":
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        mainInnerStack?.Children.RemoveAt(1);
                        mainInnerStack?.Children.Add(SetPasswordDetails.GeneratePasswordDetails(titleBar, ViewModel));
                    });
                    break;

                case "MoveToFour":
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        mainInnerStack?.Children.RemoveAt(1);
                        mainInnerStack?.Children.Add(FleetDetails.GenerateFleetDetails(titleBar, ViewModel));
                    });
                    break;

                case "AllDone":
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        mainInnerStack?.Children.RemoveAt(1);
                        mainInnerStack?.Children.Add(SignupCompleted.SignupDetailsCompleted(titleBar, ViewModel));
                    });
                    break;

                case "MoveToPairing":
                    await Navigation.PushAsync(new PairNewVehiclePage());

                    break;
                }
            };
        }
示例#2
0
        /*
         *  signup or signin with nonce.
         *  nonce is the parameter which help more accurate validation of idToken on your application server.
         *
         *  recommended way of the SIWA authentication with nonce is below.
         *  1. client gets the nonce from your application server. server should record generated nonce.
         *  2. client should use the nonce to execute SignupOrSignin(nonce, (isSignup, SIWA userInfo) => {do sending idToken and other data to your server}) method.
         *  3. application server receives the idToken included the nonce. do delete record of the nonce and validate idToken with nonce. this way gives you to accurate JWT verification and avoid replay attack.
         */
        public static void SignupOrSignin(string nonce, AuthorizationScope authorizationScope, Action <bool, UserInfo> onSucceeded, Action <string> onFailed)
        {
            switch (state)
            {
            case State.None:
                break;

            default:
                onFailed("another process running. waiting for end of:" + state);
                return;
            }

            state = State.SignUpProcessing;

            signupCompletedCallback = args =>
            {
                state = State.None;


                var userInfo = args.userInfo;;

                // success
                if (string.IsNullOrEmpty(userInfo.error))
                {
                    /*
                     *  success
                     *  {
                     *      "userId": "000692.40362e95611641bbb392d7dddc6b25ca.1447",
                     *      "email": "[email protected]",
                     *      "displayName": "xxxxx",
                     *      "authorizationCode": "c4902247f521c4104ba925bbc17143b8c.0.nwzs.l8YIwin6RbYr9aYGlRMoQg",
                     *      "idToken": "eyJraWQiOiI4NkQ4OEtmIiwiYWxnIjoiUlMyNTYifQ.eyJpc3MiOiJodHRwczovL2FwcGxlaWQuYXBwbGUuY29tIiwiYXVkIjoiY29tLmtpYWFraS50ZXN0IiwiZXhwIjoxNTg0MDExMTk1LCJpYXQiOjE1ODQwMTA1OTUsInN1YiI6IjAwMDY5Mi40MDM2MmU5NTYxMTY0MWJiYjM5MmQ3ZGRkYzZiMjVjYS4xNDQ3IiwiY19oYXNoIjoiUms5RHk4aGhvSUhUR2NTWlVjbkFhdyIsImVtYWlsIjoiOHp0OGpteTVieEBwcml2YXRlcmVsYXkuYXBwbGVpZC5jb20iLCJlbWFpbF92ZXJpZmllZCI6InRydWUiLCJpc19wcml2YXRlX2VtYWlsIjoidHJ1ZSIsImF1dGhfdGltZSI6MTU4NDAxMDU5NSwibm9uY2Vfc3VwcG9ydGVkIjp0cnVlfQ.LWDdtt-AS42QbgfO6q2zfe2uJ7rvsQNgUz8phrOO4sltT4fNPMdJDAcdpHj7wuEYUhSoC4lKSTzEyVOSqXzxHNrWah6VEki49vWmNlHObTTdEHyfh6zhjj5Keve5WWO-1s7kmPu6eEFeyz3gAbvRPpck_tTWgx6N6-oijdccTy4jdstAt5mxUtzhT-oPw8LvEC0kLpRhZyOcjfiFsMZ2AFXzkQAbl6JaKdrvSZNcgM-VbzJrfg4b_bS14FAPqKN3ZJ_ksSvyaY3ugI0NBT_rUeINugOoABwk1h1bv7RW4R66Pmg5oAGDH_m3AwKkFkltIbZyAMXsmP3HU6iMr2iquA",
                     *      "error": "",
                     *      "userDetectionStatus": 1
                     *  }
                     */

                    // Debug.Log("data:" + JsonUtility.ToJson(userInfo));

                    var publicUserInfo = new UserInfo(
                        userInfo.authorizationCode,
                        userInfo.userId,
                        userInfo.email,
                        userInfo.displayName,
                        userInfo.idToken,
                        userInfo.userDetectionStatus
                        );

                    // check if requested authorizationScope data is contained or not.
                    // if requested but not contained, the request is not first one.
                    // determine the result as "signin".
                    var isSignin = false;
                    switch (authorizationScope)
                    {
                    case AuthorizationScope.Email:
                        isSignin = string.IsNullOrEmpty(publicUserInfo.email);
                        break;

                    case AuthorizationScope.FullName:
                        isSignin = string.IsNullOrEmpty(publicUserInfo.displayName);
                        break;

                    case AuthorizationScope.EmailAndFullName:
                        isSignin = string.IsNullOrEmpty(publicUserInfo.email) && string.IsNullOrEmpty(publicUserInfo.displayName);
                        break;
                    }

                    if (isSignin)
                    {
                        // signin.
                        onSucceeded(false, publicUserInfo);
                        return;
                    }

                    // signup.
                    onSucceeded(true, publicUserInfo);
                    return;
                }

                /*
                 *  {
                 *      "userInfo": {
                 *          "userId": "",
                 *          "email": "",
                 *          "displayName": "",
                 *          "authorizationCode": "",
                 *          "idToken": "",
                 *          "error": "",
                 *          "userDetectionStatus": 0
                 *      }
                 *      "error": "The operation couldn’t be completed. (com.apple.AuthenticationServices.AuthorizationError error 1001.)"
                 *  }
                 */
                // error
                onFailed(userInfo.error);
            };

#if UNITY_EDITOR
            state = State.None;
            onSucceeded(
                true,
                new UserInfo(
                    "dummy authorizationCode",
                    "dummy userId",
                    "dummy email",
                    "dummy displayName",
                    "dummy idToken",
                    UserDetectionStatus.LikelyReal
                    )
                );
#elif UNITY_IOS
            IntPtr          cback = IntPtr.Zero;
            SignupCompleted d     = SignupCompletedCallback;
            cback = Marshal.GetFunctionPointerForDelegate(d);

            SignInWithApple_Signup(nonce, (int)authorizationScope, cback);
#endif
        }