Пример #1
0
        public async Task <AppleAccount> SignInAsync()
        {
            // Fallback to web for older iOS versions
            if (!Is13)
            {
                return(await webSignInService.SignInAsync());
            }

            AppleAccount appleAccount = default;

#if __IOS__13
            var provider = new ASAuthorizationAppleIdProvider();
            var req      = provider.CreateRequest();

            authManager = new AuthManager(UIApplication.SharedApplication.KeyWindow);

            req.RequestedScopes = new[] { ASAuthorizationScope.FullName, ASAuthorizationScope.Email };
            var controller = new ASAuthorizationController(new[] { req });

            controller.Delegate = authManager;
            controller.PresentationContextProvider = authManager;

            controller.PerformRequests();

            var creds = await authManager.Credentials;

            if (creds == null)
            {
                return(null);
            }

            appleAccount                = new AppleAccount();
            appleAccount.IdToken        = JwtToken.Decode(new NSString(creds.IdentityToken, NSStringEncoding.UTF8).ToString());
            appleAccount.Email          = creds.Email;
            appleAccount.UserId         = creds.User;
            appleAccount.Name           = NSPersonNameComponentsFormatter.GetLocalizedString(creds.FullName, NSPersonNameComponentsFormatterStyle.Default, NSPersonNameComponentsFormatterOptions.Phonetic);
            appleAccount.RealUserStatus = creds.RealUserStatus.ToString();
#endif

            return(appleAccount);
        }
Пример #2
0
        public IHttpActionResult Get()
        {
            var headers = Request.Headers;

            if (!headers.Contains("token"))
            {
                return(Ok(new { errorCode = "66", message = "not logged in" }));
            }
            if (headers.Contains("token"))
            {
                var token = headers.GetValues("token").First();
                var jwt   = new JwtToken();
                if (!jwt.VerifyToken(token))
                {
                    return(Ok(new { errorCode = "66", message = "unauthorized" }));;
                }
            }
            var payload = JwtToken.Decode(headers.GetValues("token").First());

            return(Ok(new { errorCode = "0", message = payload }));
        }