Пример #1
0
        /// <summary>
        /// This sample illustartes a simplified token exhange flow.
        /// The configurations neccessary in HelseID are:
        ///
        /// The subject-client which is an ordinary client
        /// The client is configured with:
        ///     - grant_type: authorization_code
        ///     - secret: some enterprise sertificate
        ///     - scopes: an api-scope which belongs to the api doing token exchange
        ///
        /// The api-resource being called by the subject-client.
        /// The resource is configured with:
        ///     - scopes: the api scope used by the subject client.
        ///     - user claims: pid, security_level
        ///
        ///
        /// The actor-client. This is the client doing token exchange on behalf of the api-resource.
        /// The client is configured with:
        ///     - grant_type: token_exchange
        ///     - secret: some enterprise certificate
        ///     - scopes: the scopes of other API-s the api-resource needs access to
        ///
        ///
        /// NOTE: For convenience we are using the same enterprise certificate for the subject and actor client.
        ///       In normal use cases this would be two different certificates.
        ///
        /// </summary>
        /// <returns></returns>
        public static async Task MainAsync()
        {
            var settings             = GetSettings();
            var signinService        = new SignInService(settings);
            var tokenExchangeService = new TokenExchangeService(settings);

            Console.WriteLine("+---------------------------------------+");
            Console.WriteLine("|      Token Exchange Demo Client       |");
            Console.WriteLine("+---------------------------------------+");
            Console.WriteLine("");

            Console.WriteLine("Logging in and retrieving subject access token...");


            // Authenticate user, using an enterprise certifikate as client secret
            var subjectToken = await signinService.SignIn();

            Console.WriteLine("Exchanging token...");

            // In a real-world scenarion we would pass the subject token (which
            // is an access token) on to an API, and that API would do the Token Exchange.
            // Here we do the exchange on the fly.
            var teToken = await tokenExchangeService.Exchange(subjectToken);

            Console.WriteLine("Token exchange complete.");
            PrintTokens(subjectToken, teToken);

            Console.WriteLine("Press any key...");
            Console.ReadKey();
        }
Пример #2
0
 public void TestSignIn()
 {
     string notify;
     bool   result = _signInService.SignIn(new Core.Entity.SignInRecord()
     {
         OpenId     = "1234567890",
         ActivityId = 1,
         NickName   = "lsh",
     }, out notify);
     //Assert.IsTrue(result);
 }
Пример #3
0
        public void SignIn_ValidEmail_GenerateToken()
        {
            var init = new InitializeMockContext();
            var mock = init.mock;

            var signInService = new SignInService(mock.Object);
            var result        = signInService.SignIn(new SignInCommand()
            {
                Email = "*****@*****.**", Password = "******"
            });

            Assert.AreNotEqual(result.Token, null);
            mock.Verify(m => m.SaveChanges(), Times.Once());
        }
Пример #4
0
        public async Task <SignInResult> SignIn(SignInModel signInModel)
        {
            SignInResult signInResult = await signInService.SignIn(signInModel.Email, signInModel.Password);

            if (!signInResult.Successful)
            {
                return(signInResult);
            }

            if (signInModel.StaySignedIn)
            {
                await serverHandler.StorageService.UpsertItem("authToken", signInResult.Token);
            }

            ((CustomAuthenticationStateProvider)authenticationStateProvider).MarkUserAsAuthenticated(signInResult.Token);

            return(signInResult);
        }
Пример #5
0
        /// <summary>
        ///  进行签到
        /// </summary>
        /// <param name="record"></param>
        /// <returns></returns>
        public ActionResult ToSignin(SignInRecord record)
        {
            //签到
            string notify;
            bool   result = _signInService.SignIn(record, out notify);

            if (result)
            {
                //签到上墙
                var model = _sigInRecordRespository.Get(DbConfig.DbConnStr, record.Id);
                ScreenTicker.Instance.SendSignInRecordToClient(model);
            }
            return(Json(new DataResult()
            {
                Status = result,
                Notify = notify
            }));
        }