コード例 #1
0
        public AccessToken GetAccessToken(AccessRequest accessRequest)
        {
            OrganisationKeySerDes organisationKey = ExtractOrganisationKey(accessRequest.Key);

            if (organisationKey == null)
            {
                throw new ApplicationException("Extract Organisation-Key process returned a null key.");
            }
            CheckKeyIsValid(organisationKey.Name, organisationKey.OKey);

            AuthorisationEntity authorisation = GetAuthorisation(accessRequest.AuthenticationCode);

            if (authorisation == null)
            {
                throw new ApplicationException("Could not find Authorisation entry in the database.");
            }

            AccessEnity access = CreateAccess(authorisation.UserId, accessRequest.Scope,
                                              organisationKey.Name);

            PersistAccess(access);
            DeleteAuthorisation(authorisation);

            AccessToken accessToken = CreateAccessToken(access);

            return(accessToken);
        }
コード例 #2
0
        private void DeleteAuthorisation(AuthorisationEntity authorisation)
        {
            IAuthorisationRepository authorisationRepo = AuthorisationRepoFactory.GetAuthorisationRepository(DatabaseOption.DatabaseEngine,
                                                                                                             DatabaseOption.DbConnectionString);

            authorisationRepo.DeleteAuthorisation(authorisation);
        }
コード例 #3
0
        private void PersistAuthorisation(MessageDbCore.EntityClasses.Authorisation authorisation)
        {
            IAuthorisationRepository authorisationRepo = AuthorisationRepoFactory.GetAuthorisationRepository(DatabaseOption.DatabaseEngine,
                                                                                                             DatabaseOption.DbConnectionString);

            authorisationRepo.InsertAuthorisation(authorisation);
        }
コード例 #4
0
 private MessageDbCore.EntityClasses.Authorisation CreateAuthorisation()
 {
     MessageDbCore.EntityClasses.Authorisation authorisation = new MessageDbCore.EntityClasses.Authorisation
     {
         AuthorisationCode = Guid.NewGuid(),
         StartTime         = DateTime.Now,
         EndTime           = DateTime.Now.AddDays(1),
     };
     return(authorisation);
 }
コード例 #5
0
        private AuthorisationGrant CreateAuthorisationResult(AuthorisationRequest request,
                                                             MessageDbCore.EntityClasses.Authorisation authorisation)
        {
            AuthorisationGrant grant = new AuthorisationGrant
            {
                AuthorisationCode = authorisation.AuthorisationCode,
                Scope             = request.Scope,
                Callback          = request.Callback,
            };

            return(grant);
        }
コード例 #6
0
        public AuthorisationGrant GetAuthorisationCode(AuthorisationRequest request)
        {
            User user = GetUserMatching(request.Username, request.Password);

            if (user == null)
            {
                throw new ApplicationException("Could not find user matching Username and Password.");
            }
            MessageDbCore.EntityClasses.Authorisation authorisation = CreateAuthorisation();
            PersistAuthorisation(authorisation);
            return(CreateAuthorisationResult(request, authorisation));
        }
コード例 #7
0
        private AuthorisationEntity GetAuthorisation(string authorisationCode)
        {
            Guid authorisationCodeGuid;

            if (string.IsNullOrEmpty(authorisationCode) ||
                !Guid.TryParse(authorisationCode, out authorisationCodeGuid))
            {
                return(null);
            }

            IAuthorisationRepository authorisationRepo = AuthorisationRepoFactory.GetAuthorisationRepository(DatabaseOption.DatabaseEngine,
                                                                                                             DatabaseOption.DbConnectionString);
            AuthorisationEntity authorisation = authorisationRepo.GetAuthorisationMatchingAuthCode(authorisationCodeGuid);

            return(authorisation);
        }