Beispiel #1
0
        public static async void AuthenticateWithSrpAsync(string email, string pass)
        {
            AmazonCognitoIdentityProviderConfig config = new AmazonCognitoIdentityProviderConfig();
            var provider = new AmazonCognitoIdentityProviderClient(new AnonymousAWSCredentials(), Amazon.RegionEndpoint.EUWest1);
            var userPool = new CognitoUserPool(POOL_NAME, AWS_CLIENT_ID, provider);

            var user = new CognitoUser(email, AWS_CLIENT_ID, userPool, provider);

            AuthFlowResponse authResponse;

            try
            {
                InitiateSrpAuthRequest authRequest = new InitiateSrpAuthRequest()
                {
                    Password = pass
                };

                authResponse = await user.StartWithSrpAuthAsync(authRequest).ConfigureAwait(false);
            }
            catch (Amazon.CognitoIdentityProvider.Model.NotAuthorizedException)
            {
                Console.WriteLine(email + " incorrect");
                return;
            }
            Console.WriteLine(authResponse);
        }
        /// <summary>
        /// Registration Service constructor
        /// </summary>
        /// <param name="logger"></param>
        public RegistrationService(ILogger logger)
        {
            _logger = logger;
            //string join = Environment.GetEnvironmentVariables() is Dictionary<string, string> env ? string.Join(";", env?.Select(x => x.Key + "=" + x.Value)) : "Environment.GetEnvironmentVariables()=null";
            //_logger.LogInformation($"Environment:{join}");
            // Ensure all required environment variables are provided
            CognitoClientId = Environment.GetEnvironmentVariable(COGNITO_APPLICATION_CLIENT_ID_ENVIRONMENT_VARIABLE_LOOKUP);
            if (CognitoClientId == null)
            {
                throw new Exception($"Missing required environment variable {COGNITO_APPLICATION_CLIENT_ID_ENVIRONMENT_VARIABLE_LOOKUP}");
            }

            CognitoUserPoolId = Environment.GetEnvironmentVariable(COGNITO_USER_POOL_ID_ENVIRONMENT_VARIABLE_LOOKUP);
            if (CognitoUserPoolId == null)
            {
                throw new Exception($"Missing required environment variable {COGNITO_USER_POOL_ID_ENVIRONMENT_VARIABLE_LOOKUP}");
            }
            string region = Environment.GetEnvironmentVariable(COGNITO_REGION_ENVIRONMENT_VARIABLE_LOOKUP);

            if (region == null)
            {
                throw new Exception($"Missing required environment variable {COGNITO_REGION_ENVIRONMENT_VARIABLE_LOOKUP}");
            }

            var config = new AmazonCognitoIdentityProviderConfig
            {
                AuthenticationRegion = region,
                RegionEndpoint       = RegionEndpoint.GetBySystemName(region)
            };

            Cognito = new AmazonCognitoIdentityProviderClient(config);


            InitializeCustomAttributes().Wait();
        }
        public LoginViewModel(AmazonCognitoIdentityProviderConfig idpConfig, IConfigureCognito cognitoConfig)
        {
            _idpConfig     = idpConfig;
            _cognitoConfig = cognitoConfig;

            Message       = "Please enter your credentials";
            Password      = "";
            SignInCommand = new Command(OnSignIn);
        }
Beispiel #4
0
        public App(IPlatformInitializer initializer, AmazonCognitoIdentityProviderConfig _ClientHttpFactory)
            : base(initializer)
        {
            this.ClientHttpFactory = _ClientHttpFactory;

            this.AuthApi.ClientHttpConfig = this.ClientHttpFactory;

            InitializeMainPage();
        }
Beispiel #5
0
        public App(AmazonCognitoIdentityProviderConfig idpConfig, IConfigureCognito cognitoConfig)
        {
            InitializeComponent();
            var viewModel = new LoginViewModel(idpConfig, cognitoConfig);

            MainPage = new MainPage {
                BindingContext = viewModel
            };
        }
Beispiel #6
0
        public CognitoAuthService(HttpClient httpClient,
                                  AuthenticationStateProvider authenticationStateProvider)
        {
            _authenticationStateProvider = authenticationStateProvider;

            // init cognito
            var config = new AmazonCognitoIdentityProviderConfig();

            config.HttpClientFactory = new BlazorWebAssemblyHttpClientFactory(httpClient);
            config.RegionEndpoint    = RegionEndpoint.APNortheast1;
            _provider = new AmazonCognitoIdentityProviderClient(new AnonymousAWSCredentials(), config);
            _userPool = new CognitoUserPool(PoolID, ClientID, _provider);
        }
Beispiel #7
0
        protected IAmazonCognitoIdentityProvider CreateClient(RegionEndpoint region)
        {
            var config = new AmazonCognitoIdentityProviderConfig {
                RegionEndpoint = region
            };

            Amazon.PowerShell.Utils.Common.PopulateConfig(this, config);
            this.CustomizeClientConfig(config);
            var client = new AmazonCognitoIdentityProviderClient(new AnonymousAWSCredentials(), config);

            client.BeforeRequestEvent += RequestEventHandler;
            client.AfterResponseEvent += ResponseEventHandler;
            return(client);
        }
Beispiel #8
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            Forms.Init();

            var idpConfig = new AmazonCognitoIdentityProviderConfig
            {
                HttpClientFactory = new IOSClientFactory(),
                RegionEndpoint    = RegionEndpoint.USEast1
            };

            LoadApplication(new App(idpConfig, new StaticCognitoConfiguration()));

            return(base.FinishedLaunching(app, options));
        }
Beispiel #9
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);
            Forms.Init(this, savedInstanceState);

            var idpConfig = new AmazonCognitoIdentityProviderConfig
            {
                HttpClientFactory = new AndroidClientFactory(),
                RegionEndpoint    = RegionEndpoint.USEast1
            };

            LoadApplication(new App(idpConfig, new StaticCognitoConfiguration()));
        }
Beispiel #10
0
        public App(AmazonCognitoIdentityProviderConfig _ClientHttpFactory)
        {
            InitializeComponent();

            AuthApi = new ApiCognito();
            Session = new SessionStore {
                Settings = Plugin.Settings.CrossSettings.Current
            };

            ApiCognito.PoolId           = "us-west-2_CHjCveWGb";        // Change to <Your Pool Id>
            ApiCognito.ClientId         = "1sqm1euqob2uretl0jrc961gf3"; // Change to <Your Client Id>
            ApiCognito.RegionEndpoint   = RegionEndpoint.USWest2;       // Change to <Your Region>
            ApiCognito.ClientHttpConfig = _ClientHttpFactory;

            InitializeMainPage();
        }
Beispiel #11
0
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();


            var config = new AmazonCognitoIdentityProviderConfig
            {
                HttpClientFactory = new IOSClientFactory()
            };

            config.RegionEndpoint = RegionEndpoint.USWest2; //set your Endpoint

            LoadApplication(new SaltyDog.CognitoForms.App.App(config));

            return(base.FinishedLaunching(app, options));
        }
Beispiel #12
0
 public void AddCognitoIdentityProviderService(IServiceCollection services,
                                               RegionEndpoint regionEndpoint,
                                               Credentials credentials)
 {
     services.AddSingleton <IAmazonCognitoIdentityProvider>(
         p =>
     {
         var config = new AmazonCognitoIdentityProviderConfig
         {
             RegionEndpoint = regionEndpoint
         };
         return(credentials == null ?
                new AmazonCognitoIdentityProviderClient(config) :
                new AmazonCognitoIdentityProviderClient(
                    credentials, config));
     });
 }
Beispiel #13
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            AppCenter.Start("d2de2538-ef83-4c40-861e-15aaf2b41abc", typeof(Analytics), typeof(Crashes));

            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            ClientHttpConfig = new AmazonCognitoIdentityProviderConfig
            {
                HttpClientFactory = new AndroidClientFactory()
            };
            ClientHttpConfig.RegionEndpoint = RegionEndpoint.USEast1;

            LoadApplication(new App(new AndroidInitializer(), ClientHttpConfig));
        }
Beispiel #14
0
        protected override void OnCreate(Bundle bundle)
        {
            TabLayoutResource = SaltyDog.CognitoForms.Droid.Resource.Layout.Tabbar;
            ToolbarResource   = SaltyDog.CognitoForms.Droid.Resource.Layout.Toolbar;

            base.OnCreate(bundle);

            global::Xamarin.Forms.Forms.Init(this, bundle);
            ClientHttpConfig = new AmazonCognitoIdentityProviderConfig
            {
                HttpClientFactory = new AndroidClientFactory()
            };
            ClientHttpConfig.RegionEndpoint = RegionEndpoint.USWest2; //set your Endpoint



            LoadApplication(new SaltyDog.CognitoForms.App.App(ClientHttpConfig));
        }
Beispiel #15
0
		private static IAmazonCognitoIdentityProvider CreateCognitoProvider(
			ICredentialsProvider credentialsProvider,
			ICognitoOptions<T> options
		) {
			AWSCredentials credentials = credentialsProvider.GetCredentials( options.CredentialsProfile );
			if( !string.IsNullOrWhiteSpace( options.Role ) ) {
				credentials = credentialsProvider.AssumeRole(
								credentials,
								options.Role
							);
			}

			if( !string.IsNullOrWhiteSpace( options.RegionEndpoint ) ) {
				AmazonCognitoIdentityProviderConfig config = new AmazonCognitoIdentityProviderConfig {
					RegionEndpoint = RegionEndpoint.GetBySystemName( options.RegionEndpoint )
				};
				return new AmazonCognitoIdentityProviderClient( credentials, config );
			}

			return new AmazonCognitoIdentityProviderClient( credentials );
		}