public async Task<AuthenticationTicket> ValidateTicket(IOwinRequest request, IOwinContext context, HttpClient httpClient,
            string ticket, AuthenticationProperties properties, string service)
        {
            // Now, we need to get the ticket validated
            string validateUrl = _options.CasServerUrlBase + "/validate" +
                                 "?service=" + service +
                                 "&ticket=" + Uri.EscapeDataString(ticket);

            HttpResponseMessage response = await httpClient.GetAsync(validateUrl, request.CallCancelled);

            response.EnsureSuccessStatusCode();
            string responseBody = await response.Content.ReadAsStringAsync();


            String validatedUserName = null;
            var responseParts = responseBody.Split('\n');
            if (responseParts.Length >= 2 && responseParts[0] == "yes")
                validatedUserName = responseParts[1];

            if (!String.IsNullOrEmpty(validatedUserName))
            {
                var identity = new ClaimsIdentity(_options.AuthenticationType);
                identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, validatedUserName, "http://www.w3.org/2001/XMLSchema#string", _options.AuthenticationType));
                identity.AddClaim(new Claim(ClaimTypes.Name, validatedUserName, "http://www.w3.org/2001/XMLSchema#string", _options.AuthenticationType));

                var authenticatedContext = new CasAuthenticatedContext(context, identity, properties);

                await _options.Provider.Authenticated(authenticatedContext);

                return new AuthenticationTicket(authenticatedContext.Identity, authenticatedContext.Properties);
            }

            return new AuthenticationTicket(null, properties);
        }
        public async Task <AuthenticationTicket> ValidateTicket(IOwinRequest request, IOwinContext context, HttpClient httpClient,
                                                                string ticket, AuthenticationProperties properties, string service)
        {
            // Now, we need to get the ticket validated
            string validateUrl = _options.CasServerUrlBase + "/serviceValidate" +
                                 "?service=" + service +
                                 "&ticket=" + Uri.EscapeDataString(ticket);

            HttpResponseMessage response = await httpClient.GetAsync(validateUrl, request.CallCancelled);

            response.EnsureSuccessStatusCode();
            string responseBody = await response.Content.ReadAsStringAsync();

            XDocument doc = XDocument.Parse(responseBody);

            var serviceResponse = doc.Element(_ns + "serviceResponse");
            var successNode     = serviceResponse.Element(_ns + "authenticationSuccess");

            if (successNode != null)
            {
                var    userNode          = successNode.Element(_ns + "user");
                string validatedUserName = null;
                if (userNode != null)
                {
                    validatedUserName = userNode.Value;
                }

                if (!string.IsNullOrEmpty(validatedUserName))
                {
                    var identity = BuildIdentity(_options, validatedUserName, successNode);

                    var authenticatedContext = new CasAuthenticatedContext(context, identity, properties);

                    await _options.Provider.Authenticated(authenticatedContext);

                    return(new AuthenticationTicket(authenticatedContext.Identity, authenticatedContext.Properties));
                }
            }

            return(new AuthenticationTicket(null, properties));
        }
        public async Task<AuthenticationTicket> ValidateTicket(IOwinRequest request, IOwinContext context, HttpClient httpClient,
            string ticket, AuthenticationProperties properties, string service)
        {
            // Now, we need to get the ticket validated
            string validateUrl = _options.CasServerUrlBase + "/serviceValidate" +
                                 "?service=" + service +
                                 "&ticket=" + Uri.EscapeDataString(ticket);

            HttpResponseMessage response = await httpClient.GetAsync(validateUrl, request.CallCancelled);

            response.EnsureSuccessStatusCode();
            string responseBody = await response.Content.ReadAsStringAsync();
            XDocument doc = XDocument.Parse(responseBody);

            var serviceResponse = doc.Element(_ns + "serviceResponse");
            var successNode = serviceResponse.Element(_ns + "authenticationSuccess");
            if (successNode != null)
            {
                var userNode = successNode.Element(_ns + "user");
                string validatedUserName = null;
                if (userNode != null)
                    validatedUserName = userNode.Value;

                if (!string.IsNullOrEmpty(validatedUserName))
                {
                    var identity = BuildIdentity(_options, validatedUserName, successNode);

                    var authenticatedContext = new CasAuthenticatedContext(context, identity, properties);

                    await _options.Provider.Authenticated(authenticatedContext);

                    return new AuthenticationTicket(authenticatedContext.Identity, authenticatedContext.Properties);
                }
            }

            return new AuthenticationTicket(null, properties);
        }
        public async Task <AuthenticationTicket> ValidateTicket(IOwinRequest request, IOwinContext context, HttpClient httpClient,
                                                                string ticket, AuthenticationProperties properties, string service)
        {
            // Now, we need to get the ticket validated
            string validateUrl = _options.CasServerUrlBase + "/validate" +
                                 "?service=" + service +
                                 "&ticket=" + Uri.EscapeDataString(ticket);

            HttpResponseMessage response = await httpClient.GetAsync(validateUrl, request.CallCancelled);

            response.EnsureSuccessStatusCode();
            string responseBody = await response.Content.ReadAsStringAsync();


            String validatedUserName = null;
            var    responseParts     = responseBody.Split('\n');

            if (responseParts.Length >= 2 && responseParts[0] == "yes")
            {
                validatedUserName = responseParts[1];
            }

            if (!String.IsNullOrEmpty(validatedUserName))
            {
                var identity = new ClaimsIdentity(_options.AuthenticationType);
                identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, validatedUserName, "http://www.w3.org/2001/XMLSchema#string", _options.AuthenticationType));
                identity.AddClaim(new Claim(ClaimTypes.Name, validatedUserName, "http://www.w3.org/2001/XMLSchema#string", _options.AuthenticationType));

                var authenticatedContext = new CasAuthenticatedContext(context, identity, properties);

                await _options.Provider.Authenticated(authenticatedContext);

                return(new AuthenticationTicket(authenticatedContext.Identity, authenticatedContext.Properties));
            }

            return(new AuthenticationTicket(null, properties));
        }
示例#5
0
 /// <summary>
 /// Invoked whenever Cas succesfully authenticates a user
 /// </summary>
 /// <param name="context">Contains information about the login session as well as the user <see cref="System.Security.Claims.ClaimsIdentity"/>.</param>
 /// <returns>A <see cref="Task"/> representing the completed operation.</returns>
 public virtual Task Authenticated(CasAuthenticatedContext context)
 {
     return(OnAuthenticated(context));
 }
 /// <summary>
 /// Invoked whenever Cas succesfully authenticates a user
 /// </summary>
 /// <param name="context">Contains information about the login session as well as the user <see cref="System.Security.Claims.ClaimsIdentity"/>.</param>
 /// <returns>A <see cref="Task"/> representing the completed operation.</returns>
 public virtual Task Authenticated(CasAuthenticatedContext context)
 {
     return OnAuthenticated(context);
 }