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); }
private void DeleteAuthorisation(AuthorisationEntity authorisation) { IAuthorisationRepository authorisationRepo = AuthorisationRepoFactory.GetAuthorisationRepository(DatabaseOption.DatabaseEngine, DatabaseOption.DbConnectionString); authorisationRepo.DeleteAuthorisation(authorisation); }
private void PersistAuthorisation(MessageDbCore.EntityClasses.Authorisation authorisation) { IAuthorisationRepository authorisationRepo = AuthorisationRepoFactory.GetAuthorisationRepository(DatabaseOption.DatabaseEngine, DatabaseOption.DbConnectionString); authorisationRepo.InsertAuthorisation(authorisation); }
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); }
private AuthorisationGrant CreateAuthorisationResult(AuthorisationRequest request, MessageDbCore.EntityClasses.Authorisation authorisation) { AuthorisationGrant grant = new AuthorisationGrant { AuthorisationCode = authorisation.AuthorisationCode, Scope = request.Scope, Callback = request.Callback, }; return(grant); }
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)); }
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); }