Ejemplo n.º 1
0
        public async Task <AuthorizeResponse> CreateCodeFlowResponseAsync(ValidatedAuthorizeRequest request, ClaimsPrincipal subject)
        {
            var code = new AuthorizationCode
            {
                Client  = request.Client,
                Subject = subject,

                IsOpenId        = request.IsOpenIdRequest,
                RequestedScopes = request.ValidatedScopes.GrantedScopes,
                RedirectUri     = request.RedirectUri,

                WasConsentShown      = request.WasConsentShown,
                RefreshTokenLifetime = request.Client.RefreshTokenLifetime
            };

            // store id token and access token and return authorization code
            var id = Guid.NewGuid().ToString("N");
            await _authorizationCodes.StoreAsync(id, code);

            return(new AuthorizeResponse
            {
                RedirectUri = request.RedirectUri,
                Code = id,
                State = request.State
            });
        }
Ejemplo n.º 2
0
        private async Task <string> CreateCodeAsync(ValidatedAuthorizeRequest request)
        {
            var code = new AuthorizationCode
            {
                Client              = request.Client,
                Subject             = request.Subject,
                SessionId           = request.SessionId,
                CodeChallenge       = request.CodeChallenge.Sha256(),
                CodeChallengeMethod = request.CodeChallengeMethod,

                IsOpenId        = request.IsOpenIdRequest,
                RequestedScopes = request.ValidatedScopes.GrantedScopes,
                RedirectUri     = request.RedirectUri,
                Nonce           = request.Nonce,

                WasConsentShown = request.WasConsentShown,
            };

            // store id token and access token and return authorization code
            var id = CryptoRandom.CreateUniqueId();
            await _authorizationCodes.StoreAsync(id, code);

            await RaiseCodeIssuedEventAsync(id, code);

            return(id);
        }
        public async Task InitializeAsync()
        {
            var factory = _data.Factory;
            var admin   = factory.Resolve <IAdminService>();
            var code    = TestData.AuthorizationCode(Subject);

            await admin.CreateDatabase(expireUsingIndex : false);

            await admin.Save(code.Client);

            foreach (var scope in code.RequestedScopes)
            {
                await admin.Save(scope);
            }
            await _acStore.StoreAsync("ac", code);
        }
        private async Task <string> CreateCodeAsync(ValidatedAuthorizeRequest request)
        {
            var code = new AuthorizationCode
            {
                Client  = request.Client,
                Subject = request.Subject,

                IsOpenId        = request.IsOpenIdRequest,
                RequestedScopes = request.ValidatedScopes.GrantedScopes,
                RedirectUri     = request.RedirectUri,

                WasConsentShown = request.WasConsentShown,
            };

            // store id token and access token and return authorization code
            var id = Guid.NewGuid().ToString("N");
            await _authorizationCodes.StoreAsync(id, code);

            return(id);
        }
        private async Task Setup(List <AuthorizationCode> subjectACodes, List <AuthorizationCode> subjectBCodes, List <AuthorizationCode> subjectCCodes)
        {
            List <Task> tasks = new List <Task>();

            tasks.Add(_authorizationStore.StoreAsync(RemoveKey, TestData.AuthorizationCode()));
            tasks.Add(_authorizationStore.StoreAsync(NotRemovedKey, TestData.AuthorizationCode()));
            foreach (var scope in TestData.Scopes())
            {
                tasks.Add(SaveAsync(scope));
            }
            for (int i = 0; i < 10; i++)
            {
                var code = TestData.AuthorizationCode(SubjectA);
                code.Client.ClientId = "notRevoked";
                code.Nonce           = "anr" + i;
                tasks.Add(_authorizationStore.StoreAsync("notRevokedA" + i, code));
                subjectACodes.Add(code);
                tasks.Add(SaveAsync(code.Client));
            }

            for (int i = 0; i < 10; i++)
            {
                var code = TestData.AuthorizationCode(SubjectB);
                code.Client.ClientId = "notRevoked";
                code.Nonce           = "anr" + i;
                tasks.Add(_authorizationStore.StoreAsync("notRevokedB" + i, code));
                subjectBCodes.Add(code);

                tasks.Add(SaveAsync(code.Client));
            }

            for (int i = 0; i < 10; i++)
            {
                var code = TestData.AuthorizationCode(SubjectB);
                code.Client.ClientId = "revoked";
                code.Nonce           = "ar" + i;
                tasks.Add(_authorizationStore.StoreAsync("revokedB" + i, code));
                subjectBCodes.Add(code);

                tasks.Add(SaveAsync(code.Client));
            }
            for (int i = 0; i < 10; i++)
            {
                var code = TestData.AuthorizationCode(SubjectC);
                code.Client.ClientId = "notRevoked";
                code.Nonce           = "anr" + i;
                tasks.Add(_authorizationStore.StoreAsync("notRevokedC" + i, code));
                subjectCCodes.Add(code);

                tasks.Add(SaveAsync(code.Client));
            }

            for (int i = 0; i < 10; i++)
            {
                var code = TestData.AuthorizationCode(SubjectC);
                code.Client.ClientId = "revoked";
                code.Nonce           = "ar" + i;
                tasks.Add(_authorizationStore.StoreAsync("revokedC" + i, code));
                subjectCCodes.Add(code);
                tasks.Add(SaveAsync(code.Client));
            }

            await Task.WhenAll(tasks);
        }