示例#1
0
 //Methods
 public void BaseInit()
 {
     try
     {
         if (this.Request == null || this.Request.Properties["apiSession"] == null)
         {
             return;
         }
         //ApiSession = JsonConvert.DeserializeObject<AccessTokenModel>(this.Request.Properties["apiSession"]);
         ApiSession           = (GetUserSessionByAccessTokenOutput)this.Request.Properties["apiSession"];
         PortalAPI            = WebConfigurationManager.AppSettings["PORTAL_API"];
         PortalAPISecurityKey = WebConfigurationManager.AppSettings["PORTAL_API_Security_Key"];
     }
     catch (Exception ex)
     {
         Logs.Append(ex.Message);
         //throw new Exception(ex.Message);
     }
 }
示例#2
0
        public GetUserSessionByAccessTokenOutput GetUserSessionByAccessToken(string accessToken)
        {
            try
            {
                var handler  = new JwtSecurityTokenHandler();
                var token    = handler.ReadJwtToken(accessToken).Payload.ToList();
                var username = token.Where(a => a.Key == "unique_name").Select(b => b.Value).FirstOrDefault();

                //string username = new System.Collections.Generic.Mscorlib_DictionaryDebugView<string, object>(token.Payload).Items[1].Value;
                //var accessTokenObj = _CT.aToken.Deserialize(accessToken);
                GetUserSessionByAccessTokenInput input = new GetUserSessionByAccessTokenInput();
                input.Username = username.ToString();
                RestHTTP http             = new RestHTTP();
                RestSharp.RestRequest req = new RestSharp.RestRequest("api/accounts/GetUserSessionByAccessToken", RestSharp.Method.POST);
                req.AddHeader("Authorization", "Bearer " + input.AccessToken);
                req.AddObject(input);

                RestSharp.RestClient client = new RestSharp.RestClient(WebConfigurationManager.AppSettings["AuthServerAPI"]);
                var response = client.Execute <GetUserSessionByAccessTokenOutput>(req);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    GetUserSessionByAccessTokenOutput result = JsonConvert.DeserializeObject <GetUserSessionByAccessTokenOutput>(response.Content, new ClaimConverter());
                    result.AccessToken = accessToken;
                    return(result);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
 public MedicalProfileService(GetUserSessionByAccessTokenOutput ApiSession)
 {
     _apiSession = ApiSession;
     _medicalProfileRepository = new MedicalProfileRepository();
 }