예제 #1
0
        private static void AddAccessTokenToHttpHeader <T>(
            HttpRequestMessage httpMessage,
            string profileId)
            where T : class
        {
            ISecureStore        secureStore        = (ISecureStore)Mvx.get_IoCProvider().Resolve <ISecureStore>();
            IProfileDataService profileDataService = (IProfileDataService)Mvx.get_IoCProvider().Resolve <IProfileDataService>();
            Profile             profile            = profileId != null?profileDataService.GetProfile(profileId) : profileDataService.GetActiveProfile();

            if (profile == null)
            {
                return;
            }
            TokenData tokenData = secureStore.GetTokenData(profile.Id);

            if (tokenData == null)
            {
                return;
            }
            httpMessage.Headers.Add("Authorization", "bearer " + tokenData.AccessToken);
        }
예제 #2
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);
        }