private async void Window_Loaded(object sender, RoutedEventArgs e)
      {
          var browser = new EmbeddedBrowser(webBrowser, _clientOptions.RedirectUri);

          _clientOptions.Browser = browser;

          var client = new HelseIdClient(_clientOptions);

          var result = await client.Login();

          if (result.IsError)
          {
              OnLoginError?.Invoke(this, new LoginEventArgs()
                {
                    Response = result
                });
          }
          else
          {
              OnLoginSuccess?.Invoke(this, new LoginEventArgs()
                {
                    Response      = result,
                    AccessToken   = result.AccessToken,
                    IdentityToken = result.IdentityToken,
                    IsError       = result.IsError,
                    Error         = result.Error
                });
          }
      }
Esempio n. 2
0
        private async Task Login()
        {
            if (_options == null)
            {
                MessageBox.Show("You must create a client configuration before logging in..", "Missing client configuration");
                return;
            }

            try
            {
                Dispatcher.Invoke(() =>
                {
                    if (UseJwtBearerClientAuthenticationRSA.IsChecked.HasValue &&
                        UseJwtBearerClientAuthenticationRSA.IsChecked.Value)
                    {
                        _options.SigningMethod = Common.Jwt.JwtGenerator.SigningMethod.RsaSecurityKey;
                    }
                    if (UseJwtBearerClientAuthenticationEntCert.IsChecked.HasValue &&
                        UseJwtBearerClientAuthenticationEntCert.IsChecked.Value)
                    {
                        _options.SigningMethod         = Common.Jwt.JwtGenerator.SigningMethod.X509EnterpriseSecurityKey;
                        _options.CertificateThumbprint = EnterpriseCertificateTextBox.Text;
                    }
                });

                var client = new HelseIdClient(_options);

                var result = await client.Login();

                HandleLoginResult(result);

                Dispatcher.Invoke(() =>
                {
                    if (Application.Current.MainWindow == null)
                    {
                        return;
                    }

                    Application.Current.MainWindow.Activate();
                    Application.Current.MainWindow.WindowState = WindowState.Normal;
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                MessageBox.Show(e.Message, e.StackTrace);
                throw;
            }
        }
        public async Task <string> SignIn()
        {
            var options = new HelseIdClientOptions
            {
                Authority             = _settings.Authority,
                ClientId              = _settings.ClientId,
                RedirectUri           = _settings.RedirectUri,
                Scope                 = "openid profile helseid://scopes/client/dcr https://ehelse.no/kjernejournal/nokkeladmin_api",
                FilterClaims          = false,
                Flow                  = OidcClientOptions.AuthenticationFlow.AuthorizationCode,
                ResponseMode          = OidcClientOptions.AuthorizeResponseMode.Redirect,
                CertificateThumbprint = _settings.Thumbprint,
                SigningMethod         = Common.Jwt.JwtGenerator.SigningMethod.X509EnterpriseSecurityKey
            };

            var client = new HelseIdClient(options);
            var result = await client.Login();

            return(result.AccessToken);
        }
        public async Task <LoginResult> RsaSignInWithAuthCode(string clientId, string scope)
        {
            var options = new HelseIdClientOptions
            {
                Authority     = _settings.Authority,
                ClientId      = clientId,
                RedirectUri   = _settings.RedirectUri,
                Scope         = scope,
                FilterClaims  = false,
                Flow          = OidcClientOptions.AuthenticationFlow.AuthorizationCode,
                ResponseMode  = OidcClientOptions.AuthorizeResponseMode.Redirect,
                SigningMethod = Common.Jwt.JwtGenerator.SigningMethod.RsaSecurityKey
            };

            var client = new HelseIdClient(options);

            var result = await client.Login();

            return(result);
        }
        public async Task <string> SignIn()
        {
            var options = new HelseIdClientOptions
            {
                Authority   = _settings.Authority,
                ClientId    = _settings.ClientId,
                RedirectUri = _settings.RedirectUri,
                Scope       = new[] { StandardScopes.OpenId, StandardScopes.Profile, ClientScopes.Dcr, ClientScopes.Kj }.ToSpaceSeparatedList(),
                FilterClaims          = false,
                Flow                  = OidcClientOptions.AuthenticationFlow.AuthorizationCode,
                ResponseMode          = OidcClientOptions.AuthorizeResponseMode.Redirect,
                CertificateThumbprint = _settings.Thumbprint,
                LoadProfile           = false,
                SigningMethod         = Common.Jwt.JwtGenerator.SigningMethod.X509EnterpriseSecurityKey
            };

            var client = new HelseIdClient(options);
            var result = await client.Login();

            return(result.AccessToken);
        }