public async Task <ActionResult> Index(CredentialsModel model)//
        {
            // AssurBoxEnvironments.Test targets https://sandbox.assurbox.net
            using (SecurityClient client = new SecurityClient(new AssurBoxClientOptions(AssurBoxEnvironments.Test)))
            {
                var token = await client.GetBearerToken(model.ClientID, model.ClientSecret);

                SessionManager.BearerToken = token.access_token;
                SessionManager.UserName    = token.userName;
            }
            return(View());
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the JWT token to communicate with AssurBox
        /// </summary>
        /// <returns></returns>
        public static string GetAssurBoxSecurityToken()
        {
            string token = MemoryCache.Default["ABX_TOKEN"] as string;

            if (string.IsNullOrEmpty(token))
            {
                SecurityClient id = new SecurityClient(new AssurBoxClientOptions {
                    Host = Config.AssurBoxApiBaseURL
                });
                var tokeninfo = id.GetBearerToken(Config.AssurBoxApiClientID, Config.AssurBoxApiClientSecret).Result;
                token = tokeninfo.access_token;
                MemoryCache.Default["ABX_TOKEN"] = token;
            }
            return(token);
        }