Esempio n. 1
0
 public void GetDecodedToken(out uint distance, out uint length)
 {
     if (TokenDecoder != null)
     {
         uint token = TokenDecoder.DecodeSymbol();
         length   = token / (ActualMaxDistance + 1) + ActualMinLength;
         distance = token % (ActualMaxDistance + 1);
     }
     else
     {
         distance = DistanceDecoder.DecodeSymbol();
         length   = LengthDecoder.DecodeSymbol() + ActualMinLength;
     }
 }
Esempio n. 2
0
        public void UpdateTokenData(Ekreta.Mobile.Core.Models.Profile profile, TokenData tokenData)
        {
            TokenInfo tokenInfo = (TokenInfo)JsonConvert.DeserializeObject <TokenInfo>(TokenDecoder.Decode(tokenData.AccessToken));

            profile.TokenInfo = tokenInfo;
            this.AddOrUpdate(profile);
            this._secureStore.SaveTokenData(profile.Id, tokenData);
        }
Esempio n. 3
0
        public async Task <bool> NotificationRegistrationAsync(Ekreta.Mobile.Core.Models.Profile profile)
        {
            try
            {
                if (!this._pushNotificationPlatformSpecificService.IsPushNotificationEnabledByDevice())
                {
                    throw new DisabledPushByDeviceException().SetErrorCode <DisabledPushByDeviceException>("/Users/admin/myagent/macMiniBlack3/_work/2/s/eKreta.Mobile/eKreta.Mobile.Core.Standard/Repository/DataServices/ProfileDataService.cs", 123);
                }
                string platform = this._pushNotificationHandler.Platform.ToString();
                NotificationMessageType notificationType = NotificationMessageType.All;
                string handle = this._pushNotificationHandler.Token;
                NotificationMessageSource notificationSource = NotificationMessageSource.Kreta;
                TokenData tokenData = this._secureStore.GetTokenData(profile.Id);
                if (tokenData.ExpiresAt <= DateTime.Now)
                {
                    tokenData = await((IAuthDataService)Mvx.get_IoCProvider().Resolve <IAuthDataService>()).RefreshToken(profile);
                }
                if (tokenData == null)
                {
                    return(false);
                }
                profile.TokenInfo = (TokenInfo)JsonConvert.DeserializeObject <TokenInfo>(TokenDecoder.Decode(tokenData.AccessToken));
                PushSettings pushSettings = await this._globalMobileApi.NotificationRegistrationAsync(profile.TokenInfo.InstituteCode, profile.TokenInfo.InstituteUserId, profile.TokenInfo.TutelaryId, platform, handle, profile.TokenInfo.Role, notificationSource, (int)notificationType, profile.Id);

                if (pushSettings != null)
                {
                    pushSettings.NotificationTypes = notificationType;
                    pushSettings.FirstTimePushRun  = true;
                    pushSettings.UpdateEugyintezes = true;
                    pushSettings.Token             = handle;
                    profile.PushSettings           = pushSettings;
                }
                else if (profile.PushSettings != null)
                {
                    profile.PushSettings.FirstTimePushRun = true;
                }
                else
                {
                    profile.PushSettings = new PushSettings()
                    {
                        FirstTimePushRun = true
                    }
                };
                this.AddOrUpdate(profile);
                return(pushSettings != null);
            }
            catch (DisabledPushByDeviceException ex)
            {
                ex.SetErrorCode <DisabledPushByDeviceException>("/Users/admin/myagent/macMiniBlack3/_work/2/s/eKreta.Mobile/eKreta.Mobile.Core.Standard/Repository/DataServices/ProfileDataService.cs", 180);
                throw;
            }
            catch (Exception ex)
            {
                CrossMobileAnalytics.Current.TrackException(ex, (IDictionary <string, string>)null, "ProfileDataService.NotificationRegistrationAsync", "/Users/admin/myagent/macMiniBlack3/_work/2/s/eKreta.Mobile/eKreta.Mobile.Core.Standard/Repository/DataServices/ProfileDataService.cs", 75);
                return(false);
            }
        }
Esempio n. 4
0
        protected override async Task <HttpResponseMessage> SendAsync(
            HttpRequestMessage request,
            CancellationToken cancellationToken)
        {
            // ISSUE: explicit reference operation
            // ISSUE: reference to a compiler-generated field
            int num = (^ this).\u003C\u003E1__state;
            HttpResponseMessage response;
            HttpResponseMessage result1;

            try
            {
                response = (HttpResponseMessage)null;
                try
                {
                    TaskAwaiter awaiter1 = this._semaphore.WaitAsync().GetAwaiter();
                    if (!awaiter1.IsCompleted)
                    {
                        // ISSUE: explicit reference operation
                        // ISSUE: reference to a compiler-generated field
                        (^ this).\u003C\u003E1__state = num = 0;
                        TaskAwaiter taskAwaiter = awaiter1;
                        // ISSUE: explicit reference operation
                        // ISSUE: reference to a compiler-generated field
                        (^ this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted <TaskAwaiter, AuthMessageHandler.\u003CSendAsync\u003Ed__5>(ref awaiter1, this);
                        return;
                    }
                    awaiter1.GetResult();
                    TaskAwaiter <HttpRequestMessage> taskAwaiter1;
                    HttpRequestMessage result2;
                    if (this._secureStore.GetTokenData(this._profile.Id).ExpiresAt <= DateTime.Now)
                    {
                        TaskAwaiter <TokenData> awaiter2 = ((IAuthDataService)Mvx.get_IoCProvider().Resolve <IAuthDataService>()).RefreshToken(this._profile).GetAwaiter();
                        if (!awaiter2.IsCompleted)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: reference to a compiler-generated field
                            (^ this).\u003C\u003E1__state = num = 1;
                            TaskAwaiter <TokenData> taskAwaiter2 = awaiter2;
                            // ISSUE: explicit reference operation
                            // ISSUE: reference to a compiler-generated field
                            (^ this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted <TaskAwaiter <TokenData>, AuthMessageHandler.\u003CSendAsync\u003Ed__5>(ref awaiter2, this);
                            return;
                        }
                        TokenData result3 = awaiter2.GetResult();
                        if (result3 == null)
                        {
                            result1 = (HttpResponseMessage)null;
                            goto label_26;
                        }
                        else
                        {
                            this._profile.TokenInfo = (TokenInfo)JsonConvert.DeserializeObject <TokenInfo>(TokenDecoder.Decode(result3.AccessToken));
                            TaskAwaiter <HttpRequestMessage> awaiter3 = this.CloneRequest(request, result3).GetAwaiter();
                            if (!awaiter3.IsCompleted)
                            {
                                // ISSUE: explicit reference operation
                                // ISSUE: reference to a compiler-generated field
                                (^ this).\u003C\u003E1__state = num = 2;
                                taskAwaiter1 = awaiter3;
                                // ISSUE: explicit reference operation
                                // ISSUE: reference to a compiler-generated field
                                (^ this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted <TaskAwaiter <HttpRequestMessage>, AuthMessageHandler.\u003CSendAsync\u003Ed__5>(ref awaiter3, this);
                                return;
                            }
                            result2 = awaiter3.GetResult();
                        }
                    }
                    else
                    {
                        TaskAwaiter <HttpRequestMessage> awaiter2 = this.CloneRequest(request, (TokenData)null).GetAwaiter();
                        if (!awaiter2.IsCompleted)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: reference to a compiler-generated field
                            (^ this).\u003C\u003E1__state = num = 3;
                            taskAwaiter1 = awaiter2;
                            // ISSUE: explicit reference operation
                            // ISSUE: reference to a compiler-generated field
                            (^ this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted <TaskAwaiter <HttpRequestMessage>, AuthMessageHandler.\u003CSendAsync\u003Ed__5>(ref awaiter2, this);
                            return;
                        }
                        result2 = awaiter2.GetResult();
                    }
                    TaskAwaiter <HttpResponseMessage> awaiter4 = base.SendAsync(result2, cancellationToken).GetAwaiter();
                    if (!awaiter4.IsCompleted)
                    {
                        // ISSUE: explicit reference operation
                        // ISSUE: reference to a compiler-generated field
                        (^ this).\u003C\u003E1__state = num = 4;
                        TaskAwaiter <HttpResponseMessage> taskAwaiter2 = awaiter4;
                        // ISSUE: explicit reference operation
                        // ISSUE: reference to a compiler-generated field
                        (^ this).\u003C\u003Et__builder.AwaitUnsafeOnCompleted <TaskAwaiter <HttpResponseMessage>, AuthMessageHandler.\u003CSendAsync\u003Ed__5>(ref awaiter4, this);
                        return;
                    }
                    response = awaiter4.GetResult();
                    result1  = response;
                }
                catch (InvalidOperationException ex)
                {
                    result1 = response;
                }
                catch (HttpRequestException ex)
                {
                    if (!((IConnectivity)Mvx.get_IoCProvider().Resolve <IConnectivity>()).get_IsConnected())
                    {
                        throw new NoInternetConnectionException().SetErrorCode <NoInternetConnectionException>("/Users/admin/myagent/macMiniBlack3/_work/2/s/eKreta.Mobile/eKreta.Mobile.Core.Standard/Services/Handlers/AuthMessageHandler.cs", 90);
                    }
                    throw;
                }
                finally
                {
                    if (num < 0)
                    {
                        this._semaphore.Release();
                    }
                }
            }
            catch (Exception ex)
            {
                // ISSUE: explicit reference operation
                // ISSUE: reference to a compiler-generated field
                (^ this).\u003C\u003E1__state = -2;
                response = (HttpResponseMessage)null;
                // ISSUE: explicit reference operation
                // ISSUE: reference to a compiler-generated field
                (^ this).\u003C\u003Et__builder.SetException(ex);
                return;
            }
label_26:
            // ISSUE: explicit reference operation
            // ISSUE: reference to a compiler-generated field
            (^ this).\u003C\u003E1__state = -2;
            response = (HttpResponseMessage)null;
            // ISSUE: explicit reference operation
            // ISSUE: reference to a compiler-generated field
            (^ this).\u003C\u003Et__builder.SetResult(result1);
        }
Esempio n. 5
0
 public JwtSecurityToken TokenDecrypt(string cookie)
 {
     var(tk, _) = new TokenDecoder(env).Decrypt(cookie);
     return(tk);
 }
Esempio n. 6
0
        public async Task <HttpResponseMessage> Contact(ServiceRequest serviceRequest)
        {
            HttpResponseMessage response = new HttpResponseMessage();

            // ensure we have a valid Identity Token, i.e. the user belongs to this exchange
            var token = (AppIdentityToken)AuthToken.Parse(serviceRequest.token);

            // demonstrates how to decode the token so that it can be inspected
            var idToken = TokenDecoder.Decode(serviceRequest.token);

            try
            {
                // Validate the user identity token. This validation ensures the request came from the Office add-in and not from a rogue request from another source.
                // This does not stop DOS but it does make sure the user does not have access to the Epicor APIs
                ValidateIdentity(token);

                // If the token is invalid, Validate will throw an exception. If the service reaches
                // this line, the token is valid.

                string credentials = string.Empty;

                // Check to see if the uniqued ID is in the cache.
                if (idCache.ContainsKey(token.UniqueUserIdentification))
                {
                    // the user has already logged in within Outlook session so use those credentials
                    credentials = idCache[token.UniqueUserIdentification];
                }
                // If the unique ID is not found, check to see if the request contains a username and password.
                else if (!string.IsNullOrEmpty(serviceRequest.userName) && !string.IsNullOrEmpty(serviceRequest.password))
                {
                    // if a username and password are present then convert to the format expected by the API, in this case Base64 - Basic Authentication
                    credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format("{0}:{1}", serviceRequest.userName, serviceRequest.password)));
                    // cache the credentials in the static dictionary so that they can be retrieved on the next request. This session is valid for the lifetime of the user session.
                    idCache.Add(token.UniqueUserIdentification, credentials);
                }
                else
                {
                    // if this status code is changed to another value, then the check in the fail outcome in the add-in needs to be cahnged as well.
                    response.StatusCode = HttpStatusCode.Unauthorized;
                }

                // finally if the token is valid and credentials have been supplied then make the call to the Epicor API
                if (!string.IsNullOrEmpty(credentials))
                {
                    using (var client = new HttpClient())
                    {
                        // Note - once Epicor have an API endpoint that fits the data model requested by the add-in then the URL will need to change and the request.context value applied as a filter
                        var url = string.Format(@"{0}{1}'", " https://13.89.62.5/ERP101500/api/v1/BaqSvc/CustomerSnapshot?$filter=CustCnt_EMailAddress eq '", serviceRequest.context);

                        HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url);

                        // basic authorization
                        request.Headers.Authorization = new AuthenticationHeaderValue("Basic", credentials);

                        // added to avoid local host ssl certificate errors - should be removed once 'proper' certificate is in place.
                        ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };

                        // wait for the response
                        response = await client.SendAsync(request);
                    }
                }
            }
            catch (TokenValidationException ex)
            {
                // an error in the token suggests the user does not have authorization to call the API
                response.StatusCode = HttpStatusCode.Unauthorized;
            }
            catch (Exception ex)
            {
                // any other error needs to be handled gracefully and the 'correct' status code applied
                response.StatusCode = HttpStatusCode.InternalServerError;
            }

            return(response);
        }
        public void UpdateTokenData(ProfileRealm profile, TokenData tokenData)
        {
            TokenInfoRealm tokenInfoRealm = (TokenInfoRealm)JsonConvert.DeserializeObject <TokenInfoRealm>(TokenDecoder.Decode(tokenData.AccessToken));

            profile.TokenInfo = tokenInfoRealm;
            this.AddOrUpdate(profile, (Action <ProfileRealm>)null);
            this._secureStore.SaveTokenData(profile.Id, tokenData);
        }
Esempio n. 8
0
        internal override void Migrate(ISettings appSettings, ISecureStore secureStore = null)
        {
            JsonSerializerSettings serializerSettings1 = new JsonSerializerSettings();

            serializerSettings1.set_Error((EventHandler <ErrorEventArgs>)((sender, args) => args.get_ErrorContext().set_Handled(true)));
            JsonSerializerSettings serializerSettings2 = serializerSettings1;
            string valueOrDefault          = appSettings.GetValueOrDefault("settings_profiles_key", (string)null, (string)null);
            IEnumerable <Profile> profiles = string.IsNullOrEmpty(valueOrDefault) ? (IEnumerable <Profile>) new List <Profile>() : (IEnumerable <Profile>)JsonConvert.DeserializeObject <IEnumerable <Profile> >(valueOrDefault, serializerSettings2);

            foreach (Profile profile in profiles)
            {
                TokenInfo tokenInfo = (TokenInfo)JsonConvert.DeserializeObject <TokenInfo>(TokenDecoder.Decode(secureStore.GetTokenData(profile.Id).AccessToken));
                profile.TokenInfo = tokenInfo;
            }
            appSettings.AddOrUpdateValue("settings_profiles_key", JsonConvert.SerializeObject((object)profiles), (string)null);
        }
Esempio n. 9
0
        public async Task <ProfileRealm> Login(
            InstituteRealm institute,
            string username,
            string password)
        {
            if (!this.IsInstituteValid(institute))
            {
                throw new InvalidInstitudeDataException(nameof(institute)).SetErrorCode <InvalidInstitudeDataException>("/Users/admin/myagent/macMiniBlack3/_work/2/s/eKreta.Mobile/eKreta.Mobile.Core.Standard/Repository/DataServices/Login/AuthDbDataService.cs", 82);
            }
            if (!this.IsUserNameValid(username))
            {
                throw new ArgumentException(nameof(username));
            }
            if (!this.IsPasswordValid(password))
            {
                throw new ArgumentException(nameof(password));
            }
            TokenData tokenAsync = await this._mobileApi.GetTokenAsync(institute.Url, username, password, institute.InstituteCode);

            TokenInfoRealm tokenInfo = new TokenInfoRealmMapper().To((Ekreta.Mobile.Core.Models.TokenInfo)JsonConvert.DeserializeObject <Ekreta.Mobile.Core.Models.TokenInfo>(TokenDecoder.Decode(tokenAsync.AccessToken)));

            switch (this._tokenValidator.Validate(tokenInfo))
            {
            case TokenValidation.VALID:
                this.DeleteOldSchoolYearIdProfiles(tokenInfo);
                return(this.ProcessValidToken(institute, tokenAsync, tokenInfo));

            case TokenValidation.INVALID_USER_ROLE:
                throw new UserRoleException("Invalid User Role").SetErrorCode <UserRoleException>("/Users/admin/myagent/macMiniBlack3/_work/2/s/eKreta.Mobile/eKreta.Mobile.Core.Standard/Repository/DataServices/Login/AuthDbDataService.cs", 103);

            default:
                throw new LoginException("Invalid TokenData").SetErrorCode <LoginException>("/Users/admin/myagent/macMiniBlack3/_work/2/s/eKreta.Mobile/eKreta.Mobile.Core.Standard/Repository/DataServices/Login/AuthDbDataService.cs", 107);
            }
        }