Пример #1
0
        public HttpResponseMessage SignInCallBack(string callback)
        {
            diagnostics.WriteInformationTrace(TraceEventId.InboundParameters,
                                              "Client callback uri:{0}", callback);

            ClaimsPrincipal  principal = this.User as ClaimsPrincipal;
            BootstrapContext context   = principal.Identities.First().BootstrapContext as BootstrapContext;
            JWTSecurityToken jwtToken  = context.SecurityToken as JWTSecurityToken;

            UriBuilder builder = new UriBuilder(new Uri(callback));


            TimeSpan span    = jwtToken.ValidTo.Subtract(jwtToken.ValidFrom);
            double   seconds = span.TotalSeconds;

            string queryparam = string.Format("{0}={1}&{2}={3}", Constants.JWTCOOKIETOKEN_PARAM, HttpUtility.UrlEncode(jwtToken.RawData), Constants.JWTCOOKIETOKEN_VALIDTO_PARAM, HttpUtility.UrlEncode(seconds.ToString()));

            builder.Query = queryparam;

            var response = Request.CreateResponse(HttpStatusCode.Moved);

            response.Headers.Location = builder.Uri;

            diagnostics.WriteVerboseTrace(TraceEventId.OutboundParameters,
                                          "Redirect Uri post authentication process:{0}",
                                          response.Headers.Location);
            return(response);
        }
Пример #2
0
 /// <summary>
 /// Send asynchronous method.
 /// </summary>
 /// <param name="request">Request object.</param>
 /// <param name="cancellationToken">CancellationToken object.</param>
 /// <returns>Response message.</returns>
 protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
 {
     diagnostics.WriteVerboseTrace(TraceEventId.InboundParameters,
                                   "HttpMethod:{0}, Url:{1}", request.Method.ToString(), request.RequestUri.AbsoluteUri);
     return(request.Headers.Contains(Origin) ?
            this.ProcessCorsRequest(request, ref cancellationToken) :
            base.SendAsync(request, cancellationToken));
 }
Пример #3
0
        public HttpResponseMessage GetUsersByNameIdentifier()
        {
            string         message        = string.Empty;
            string         nameIdentifier = string.Empty;
            HttpStatusCode status         = HttpStatusCode.OK;

            try
            {
                // Check if the user service is valid
                Check.IsNotNull(this.userService, "userService");
                nameIdentifier = Helpers.IdentityHelper.GetNameClaimTypeValue(this.User as ClaimsPrincipal);

                diagnostics.WriteVerboseTrace(TraceEventId.InboundParameters,
                                              "Retrieving user with name identifier:{0}",
                                              nameIdentifier);

                User retrievedUser = this.userService.GetUserWithRolesByNameIdentifier(nameIdentifier);
                return(Request.CreateResponse <UserInformation>(status, new UserInformation(retrievedUser)));
            }
            catch (ArgumentNullException ane)
            {
                if (ane.ParamName.Equals("userService"))
                {
                    message = MessageStrings.User_Service_Is_Null;
                    status  = HttpStatusCode.InternalServerError;
                }
            }
            catch (ArgumentException ae)
            {
                message = string.Format(CultureInfo.CurrentCulture, MessageStrings.Argument_Error_Message_Template, ae.ParamName);
                status  = HttpStatusCode.BadRequest;
            }
            catch (UserNotFoundException)
            {
                message = MessageStrings.User_Not_Found;
                status  = HttpStatusCode.NotFound;
                diagnostics.WriteErrorTrace(TraceEventId.Exception,
                                            "User with nameidentifier {0} not found",
                                            nameIdentifier);
            }

            return(Request.CreateErrorResponse(status, message));
        }