Exemplo n.º 1
0
        private string GetUserRegistrationEmailBody(UserInfo user)
        {
            string securityToken = m_TokenProvider.GenerateAuthorizationToken(user.Id);

            securityToken = HttpUtility.UrlEncode(securityToken);

            string setPasswordUrl = null;

            switch (user.UserType)
            {
            case (UserType.Admin):
                setPasswordUrl = ConfigurationManager.AppSettings["AdminUserRegistrationUrl"];
                break;

            default:
                setPasswordUrl = ConfigurationManager.AppSettings["UserRegistrationUrl"];
                break;
            }


            List <Tuple <string, string> > tagValues = new List <Tuple <string, string> >();

            tagValues.Add(new Tuple <string, string>("{{securityToken}}", securityToken));
            tagValues.Add(new Tuple <string, string>("{{setPasswordUrl}}", setPasswordUrl));

            string fileContents = Templates.UserRegistrationTemplate;

            foreach (Tuple <string, string> tagValue in tagValues)
            {
                fileContents = fileContents.Replace(tagValue.Item1, tagValue.Item2);
            }

            return(fileContents);
        }
Exemplo n.º 2
0
        public HttpResponseMessage Get()
        {
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Accepted);

            try
            {
                //get the basic auth credentials
                string basicAuthHeader = GetBasicAuthValue(Request.Headers.Authorization);

                //find a user that matches
                UserInfo authenticatedUser = GetUser(basicAuthHeader);

                //create security token
                string securityToken = m_TokenProvider.GenerateAuthorizationToken(authenticatedUser.Id);

                var content = new StringContent(securityToken);
                content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
                response         = Request.CreateResponse(HttpStatusCode.OK);
                response.Content = content;
            }
            catch (AuthenticationException ex)
            {
                response = Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message);
            }
            catch (SecurityException ex)
            {
                response = Request.CreateErrorResponse(HttpStatusCode.Unauthorized, ex.Message);
            }
            catch (Exception ex)
            {
                response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
            }

            return(response);
        }
Exemplo n.º 3
0
        public async Task <SerializedAuthorizationToken> Authenticate(string username, string password)
        {
            User user = await _usernamePasswordAuthenticationProvider.Authenticate(username, password);

            IEnumerable <Permission> permissions = await _permissionAuthorizationProvider.GetAuthorizationForUser(user);

            SerializedAuthorizationToken serializedAuthorizationToken = await _authorizationTokenProvider.GenerateAuthorizationToken(user, permissions);

            return(serializedAuthorizationToken);
        }