Exemplo n.º 1
0
        /// <summary>
        /// Method: Add
        /// Description: It is used to add new token to parnerauthtoken table
        /// </summary>
        /// <param name="item"></param>
        public PartnerAuthTokens Add(PartnerAuthTokens item)
        {
            //Get AuthTokens by auth_id
            var entity = Find(item.auth_id);

            if (entity == null)
            {
                _context.PartnerAuthTokens.Add(item);
                _context.SaveChanges();

                //attach resource reference
                _context.Entry(item).Reference(e => e.Resource).Load();
            }
            else
            {
                entity.access_token          = item.access_token;
                entity.refresh_token         = item.refresh_token;
                entity.token_type            = item.token_type;
                entity.user_id               = item.user_id;
                entity.session_nonce         = item.session_nonce;
                entity.expires_in            = item.expires_in;
                _context.Entry(entity).State = EntityState.Modified;
                _context.SaveChanges();
            }

            //assign resource
            item.redirect_url = entity.redirect_url;
            item.Resource     = entity.Resource;
            return(item);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Method: Reload
 /// Description: It is used to reload PartnerAuthTokens entity
 /// </summary>
 /// <param name="entity"></param>
 public void Reload(PartnerAuthTokens entity)
 {
     if (entity != null)
     {
         _context.Entry(entity).Reload();
         _context.Entry(entity).Reference(e => e.Resource).Load();
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Method: Add
        /// Description: It is used to add new resource to resources table when provisioning the addon
        /// </summary>
        /// <param name="item"></param>
        public void Add(Resources item, OauthGrant?oauthGrant)
        {
            using (var transaction = _context.Database.BeginTransaction())
            {
                try
                {
                    Console.WriteLine("Resource: " + JsonConvert.SerializeObject(item));
                    Console.WriteLine("Resource add starts");
                    _context.Resources.Add(item);
                    Console.WriteLine("Resource add ended");

                    HerokuAuthToken authToken = default(HerokuAuthToken);
                    if (oauthGrant.HasValue)
                    {
                        Console.WriteLine("Auth-Token get starts");
                        authToken = HerokuApi.GetAddonAccessTokenSync(oauthGrant.Value.code, oauthGrant.Value.type);
                        if (!authToken.IsNull())
                        {
                            Console.WriteLine("Auth-Token=> {0}:{1}", authToken.access_token, authToken.refresh_token);
                        }
                        else
                        {
                            throw new ArgumentNullException("Heroku access token not able to get");
                        }
                        Console.WriteLine("Auth-Token get ended");
                    }
                    else
                    {
                        Console.WriteLine("OAuth-Grant is null");
                        throw new ArgumentNullException("OAuth-Grant is null");
                    }

                    authToken.auth_id = item.uuid;
                    PartnerAuthTokens pAuthToken = authToken.ToPartnerAuthToken();
                    pAuthToken.oauth_code       = oauthGrant.Value.code;
                    pAuthToken.oauth_type       = oauthGrant.Value.type;
                    pAuthToken.oauth_expired_in = DateTime.Now.AddSeconds(280);
                    Console.WriteLine("AuthToken: " + JsonConvert.SerializeObject(pAuthToken));
                    Console.WriteLine("AuthToken add starts");
                    _context.PartnerAuthTokens.Add(pAuthToken);
                    Console.WriteLine("AuthToken add ended");
                    _context.SaveChanges();
                    transaction.Commit();
                    if (!authToken.IsNull())
                    {
                        var task = HerokuApi.AddUpdateMainAppConfigByResourceId(item.uuid, authToken.access_token);
                        task.Wait();
                    }
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw ex;
                }
            }
        }
Exemplo n.º 4
0
        public void Update(PartnerAuthTokens item)
        {
            //Get PartnerAuthTokens by auth_id
            var entity = Find(item.auth_id);

            if (entity != null)
            {
                entity.access_token          = item.access_token;
                entity.refresh_token         = item.refresh_token;
                entity.token_type            = item.token_type;
                entity.user_id               = item.user_id;
                entity.session_nonce         = item.session_nonce;
                entity.expires_in            = item.expires_in;
                _context.Entry(entity).State = EntityState.Modified;
                _context.SaveChanges();
            }
        }
Exemplo n.º 5
0
        public void UpdateReturnUrl(string authId, string returnUrl)
        {
            //Get AuthTokens by auth_id
            var entity = Find(authId);

            if (entity == null)
            {
                entity                  = new PartnerAuthTokens();
                entity.auth_id          = authId;
                entity.access_token     = "";
                entity.refresh_token    = "";
                entity.expires_in       = DateTime.MinValue;
                entity.oauth_expired_in = DateTime.MinValue;
                entity.redirect_url     = returnUrl;
                _context.PartnerAuthTokens.Add(entity);
                _context.SaveChanges();
            }
            else
            {
                entity.redirect_url          = returnUrl;
                _context.Entry(entity).State = EntityState.Modified;
                _context.SaveChanges();
            }
        }