Ejemplo n.º 1
0
        public static async Task MainAsync()
        {
            var settings = InitSettings();

            var dcrService    = new DcrService(settings);
            var kjService     = new KjernejournalService(settings);
            var signinService = new SigninService(settings);

            Console.WriteLine("+-----------------------+");
            Console.WriteLine("|      HIDEnabler       |");
            Console.WriteLine("+-----------------------+");
            Console.WriteLine("");

            Console.WriteLine("Signing in with enterprise certificate");
            var accessToken = await signinService.SignIn();

            Console.WriteLine("AccessToken: ");
            Console.WriteLine(accessToken.DecodeToken());

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
            Console.Clear();

            Console.WriteLine("Creating dcr client");

            var client = await dcrService.CreateClient(accessToken, settings.GrantType, settings.RedirectUri, settings.LogoutUri, settings.Scopes.FromSpaceSeparatedToList());

            var clientId = client.ClientId;

            Console.WriteLine("Created client with dcr api:");
            Console.WriteLine("Clientid:     " + client.ClientId);
            Console.WriteLine("GrantType:    " + string.Join(",", client.GrantTypes.ToList()));
            Console.WriteLine("RedirectUris: " + string.Join(",", client.RedirectUris));
            Console.WriteLine("Scopes:       " + string.Join(",", client.AllowedScopes));

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
            Console.Clear();

            var orgNumbers = await kjService.GetOrgNumbers(accessToken);

            // Let user choose orgnumber and return
            var orgNumber = ChooseOrgNumber(orgNumbers);

            await kjService.SetOrgNumber(accessToken, clientId, orgNumber.Nr);

            Console.Clear();
            Console.WriteLine("Signing in with dcr client");
            //Try to log in with the new configuration
            var loginResponse = await signinService.RsaSignInWithAuthCode(clientId, settings.Scopes);

            Console.WriteLine("Signin complete. Recieved access token:");
            Console.WriteLine(loginResponse.AccessToken.DecodeToken());

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        public IActionResult Signin(LoginBindingModel model, HttpResponse response, HttpSession session)
        {
            var service = new SigninService(Data.Data.Context);

            var user = service.GetCorrespondingUser(model);

            if (user == null)
            {
                this.Redirect(response, "/users/signin");
                return(null);
            }

            service.AddLogin(user, session);

            this.Redirect(response, "/home/indexlogged");
            return(null);
        }