예제 #1
0
        public async Task <RequestResult> DeleteUnConfirmedUser(string username, string password)
        {
            RequestResult result = new RequestResult();

            try
            {
                CognitoUserPool userPool = new CognitoUserPool(this.POOL_ID, this.CLIENTAPP_ID, provider);
                Amazon.Extensions.CognitoAuthentication.CognitoUser user = new Amazon.Extensions.CognitoAuthentication.CognitoUser(username, this.CLIENTAPP_ID, userPool, provider);


                AdminDeleteUserRequest req = new AdminDeleteUserRequest()
                {
                    Username = username, UserPoolId = POOL_ID
                };
                AdminDeleteUserResponse response = await provider.AdminDeleteUserAsync(req);


                if (response.HttpStatusCode == HttpStatusCode.OK)
                {
                    result.Status  = true;
                    result.Message = "Deleted Successfully";
                }
            }
            catch (Exception ex)
            {
                result.Status  = false;
                result.Message = ex.Message;
            }

            return(result);
        }
예제 #2
0
        public async Task <string> LoginAsync(string username, string password)
        {
            CognitoUserPool userPool = new CognitoUserPool(this.POOL_ID, this.CLIENTAPP_ID, provider);

            Amazon.Extensions.CognitoAuthentication.CognitoUser user = new Amazon.Extensions.CognitoAuthentication.CognitoUser(username, this.CLIENTAPP_ID, userPool, provider);

            InitiateSrpAuthRequest authRequest = new InitiateSrpAuthRequest()
            {
                Password = password
            };

            AuthFlowResponse authResponse = await user.StartWithSrpAuthAsync(authRequest).ConfigureAwait(false);

            if (authResponse.AuthenticationResult != null)
            {
                return(authResponse.AuthenticationResult.RefreshToken);
            }

            //var authReq = new AdminInitiateAuthRequest
            //{
            //    UserPoolId = POOL_ID,
            //    ClientId = CLIENTAPP_ID,
            //    AuthFlow = AuthFlowType.ADMIN_NO_SRP_AUTH
            //};
            //authReq.AuthParameters.Add("USERNAME", userName.ToLower());
            //authReq.AuthParameters.Add("PASSWORD", password);

            //AdminInitiateAuthResponse authResp = await provider.AdminInitiateAuthAsync(authReq);

            return(authResponse.AuthenticationResult.IdToken);
        }
        /// <summary>
        /// Creates an instance of CognitoDevice
        /// </summary>
        /// <param name="device">A DeviceType object to create the CognitoDevice from</param>
        /// <param name="user">The CognitoUser associated with the device</param>
        public CognitoDevice(DeviceType device, CognitoUser user)
        {
            if (device == null)
            {
                throw new ArgumentNullException("device", "Device cannot be null.");
            }

            this.DeviceKey         = device.DeviceKey;
            this.CreateDate        = device.DeviceCreateDate;
            this.LastModified      = device.DeviceLastModifiedDate;
            this.LastAuthenticated = device.DeviceLastAuthenticatedDate;
            this.User             = user;
            this.DeviceAttributes = CreateDictionaryFromAttributeList(device.DeviceAttributes);
        }
예제 #4
0
        public async Task <RequestResult> ChangePassword(string username, string oldpassword, string newpassword)
        {
            RequestResult result = new RequestResult();

            result = await this.AuthnicateUser(username, oldpassword);

            if (result.Status)
            {
                Amazon.Extensions.CognitoAuthentication.CognitoUser user = (Amazon.Extensions.CognitoAuthentication.CognitoUser)result.Data;
                await user.ChangePasswordAsync(oldpassword, newpassword);

                result.Message = "Password Changed Successfully";
            }

            return(result);
        }
예제 #5
0
        public async Task <RequestResult> UserSignOut(string username, string password)
        {
            RequestResult result = new RequestResult();

            try
            {
                result = await this.AuthnicateUser(username, password);

                if (result.Status)
                {
                    Amazon.Extensions.CognitoAuthentication.CognitoUser user = (Amazon.Extensions.CognitoAuthentication.CognitoUser)result.Data;
                    await user.GlobalSignOutAsync();
                }
            }
            catch (Exception ex)
            {
                result.Status = false;
            }

            return(result);
        }
        /// <summary>
        /// Creates an instance of CognitoDevice
        /// </summary>
        /// <param name="deviceKey">The device key for the device</param>
        /// <param name="deviceAttributes">The attributes for the device</param>
        /// <param name="createDate">The creation date for the device</param>
        /// <param name="lastModified">The last modified date for the device</param>
        /// <param name="lastAuthenticated">The last authenticated date for the device</param>
        /// <param name="user">The CognitoUser associated with the device</param>
        public CognitoDevice(string deviceKey,
                             IDictionary <string, string> deviceAttributes,
                             DateTime createDate,
                             DateTime lastModified,
                             DateTime lastAuthenticated,
                             CognitoUser user)
        {
            if (deviceKey == null)
            {
                throw new ArgumentNullException("deviceKey", "deviceKey cannot be null.");
            }

            if (deviceAttributes == null)
            {
                throw new ArgumentNullException("deviceAttributes", "deviceAttributes cannot be null.");
            }

            this.DeviceKey         = deviceKey;
            this.DeviceAttributes  = new Dictionary <string, string>(deviceAttributes);
            this.CreateDate        = createDate;
            this.LastModified      = lastModified;
            this.LastAuthenticated = lastAuthenticated;
            this.User = user;
        }
예제 #7
0
        public async Task <RequestResult> UpdatePassword(string username, string code, string newpassword)
        {
            RequestResult result = new RequestResult();

            try
            {
                CognitoUserPool userPool = new CognitoUserPool(this.POOL_ID, this.CLIENTAPP_ID, provider);

                Amazon.Extensions.CognitoAuthentication.CognitoUser user = new Amazon.Extensions.CognitoAuthentication.CognitoUser(username, this.CLIENTAPP_ID, userPool, provider);

                await user.ConfirmForgotPasswordAsync(code, newpassword);

                result.Data    = user;
                result.Status  = true;
                result.Message = "Password Updated Successfully";
            }
            catch (Exception ex)
            {
                result.Status  = false;
                result.Message = ex.Message;
            }

            return(result);
        }