Skip to content

Commit

Permalink
Merge pull request #229 from cactacea/#138
Browse files Browse the repository at this point in the history
Integrate Filhouette for authentication (#138)
  • Loading branch information
takeshishimada authored Jul 14, 2019
2 parents a70fd49 + a16190e commit e1e9364
Show file tree
Hide file tree
Showing 89 changed files with 1,311 additions and 930 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import com.twitter.finagle.oauth2.OAuthError
import com.twitter.finagle.{OAuth2, Service, SimpleFilter}
import com.twitter.inject.Logging
import com.twitter.util.Future
import io.github.cactacea.backend.core.domain.repositories.SessionsRepository
import io.github.cactacea.backend.core.domain.repositories.AccountsRepository
import io.github.cactacea.backend.utils.auth.CactaceaContext

@Singleton
class OAuthFilter @Inject()(
dataHandler: OAuthHandler,
sessionsRepository: SessionsRepository
accountsRepository: AccountsRepository
) extends SimpleFilter[Request, Response] with OAuth2 with Logging {

override def apply(request: Request, service: Service[Request, Response]): Future[Response] = {
Expand All @@ -22,9 +22,9 @@ class OAuthFilter @Inject()(
case false =>
authorize(request, dataHandler) flatMap { auth =>
val expiresIn = auth.user.expiresIn
sessionsRepository.checkAccountStatus(auth.user.accountId.toSessionId, expiresIn).flatMap({_ =>
accountsRepository.find(auth.user.accountId.toSessionId, expiresIn).flatMap({ a =>
CactaceaContext.setAuthenticated(true)
CactaceaContext.setId(auth.user.accountId.toSessionId)
CactaceaContext.setAccount(a)
service(request)
})
} handle {
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ lazy val server = (project in file("server"))
.settings(libraryDependencies ++= Dependencies.log)
.enablePlugins(BuildInfoPlugin)
.dependsOn(core % "compile->compile;test->test")
.dependsOn(finagger)
.dependsOn(finagger, filhouette)


lazy val core = (project in file("core"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ USE `${schema}` ;
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `${schema}`.`mediums` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`key` VARCHAR(1024) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NOT NULL,
`uri` VARCHAR(2048) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NOT NULL,
`key` VARCHAR(1024) NOT NULL,
`uri` VARCHAR(2048) NOT NULL,
`width` INT(11) NOT NULL,
`height` INT(11) NOT NULL,
`size` BIGINT(20) NOT NULL,
Expand All @@ -45,19 +45,18 @@ DEFAULT CHARACTER SET = utf8mb4;
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `${schema}`.`accounts` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`account_name` VARCHAR(50) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NOT NULL,
`account_name` VARCHAR(50) NOT NULL,
`display_name` VARCHAR(50) NOT NULL DEFAULT ' ',
`password` VARCHAR(255) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NOT NULL,
`follow_count` BIGINT(20) NOT NULL DEFAULT '0',
`profile_image` BIGINT(20) NULL DEFAULT NULL,
`profile_image_url` VARCHAR(2083) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NULL DEFAULT NULL,
`profile_image_url` VARCHAR(2083) NULL DEFAULT NULL,
`follower_count` BIGINT(20) NOT NULL DEFAULT '0',
`friend_count` BIGINT(20) NOT NULL DEFAULT '0',
`feed_count` BIGINT(20) NOT NULL DEFAULT '0',
`web` VARCHAR(2083) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NULL DEFAULT NULL,
`web` VARCHAR(2083) NULL DEFAULT NULL,
`birthday` BIGINT(20) NULL DEFAULT NULL,
`location` VARCHAR(255) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NULL DEFAULT NULL,
`bio` VARCHAR(1024) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NULL DEFAULT NULL,
`location` VARCHAR(255) NULL DEFAULT NULL,
`bio` VARCHAR(1024) NULL DEFAULT NULL,
`account_status` TINYINT(4) NOT NULL DEFAULT '0',
`signed_out_at` BIGINT(20) NULL DEFAULT NULL,
PRIMARY KEY (`id`),
Expand All @@ -75,7 +74,7 @@ DEFAULT CHARACTER SET = utf8mb4;
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `${schema}`.`feeds` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`message` VARCHAR(1000) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NOT NULL,
`message` VARCHAR(1000) NOT NULL,
`by` BIGINT(20) NOT NULL,
`like_count` BIGINT(20) NOT NULL,
`comment_count` BIGINT(20) NOT NULL,
Expand Down Expand Up @@ -116,7 +115,7 @@ DEFAULT CHARACTER SET = utf8mb4;
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `${schema}`.`groups` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(1000) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NULL DEFAULT NULL,
`name` VARCHAR(1000) NULL DEFAULT NULL,
`privacy_type` TINYINT(4) NOT NULL,
`invitation_only` TINYINT(4) NOT NULL,
`direct_message` TINYINT(4) NOT NULL,
Expand Down Expand Up @@ -175,7 +174,7 @@ CREATE TABLE IF NOT EXISTS `${schema}`.`messages` (
`by` BIGINT(20) NOT NULL,
`group_id` BIGINT(20) NOT NULL,
`message_type` TINYINT(4) NOT NULL,
`message` VARCHAR(1000) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NULL DEFAULT NULL,
`message` VARCHAR(1000) NULL DEFAULT NULL,
`medium_id` BIGINT(20) NULL DEFAULT NULL,
`stamp_id` BIGINT(20) NULL DEFAULT NULL,
`account_count` BIGINT(20) NOT NULL DEFAULT '0',
Expand Down Expand Up @@ -236,7 +235,7 @@ CREATE TABLE IF NOT EXISTS `${schema}`.`account_reports` (
`account_id` BIGINT(20) NOT NULL,
`by` BIGINT(20) NOT NULL,
`report_type` TINYINT(4) NOT NULL,
`report_content` VARCHAR(1000) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NULL DEFAULT NULL,
`report_content` VARCHAR(1000) NULL DEFAULT NULL,
`reported_at` BIGINT(20) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE INDEX `UNIQUE` (`account_id` ASC, `report_type` ASC, `by` ASC),
Expand Down Expand Up @@ -295,10 +294,10 @@ DEFAULT CHARACTER SET = utf8mb4;
-- Table `${schema}`.`clients`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `${schema}`.`clients` (
`id` VARCHAR(80) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NOT NULL,
`secret` VARCHAR(80) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NULL DEFAULT NULL,
`redirect_uri` VARCHAR(2000) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NOT NULL,
`scope` VARCHAR(2000) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NULL DEFAULT NULL,
`id` VARCHAR(80) NOT NULL,
`secret` VARCHAR(80) NULL DEFAULT NULL,
`redirect_uri` VARCHAR(2000) NOT NULL,
`scope` VARCHAR(2000) NULL DEFAULT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4;
Expand All @@ -309,7 +308,7 @@ DEFAULT CHARACTER SET = utf8mb4;
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `${schema}`.`grant_types` (
`id` TINYINT(4) NOT NULL,
`grant_type` VARCHAR(20) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NOT NULL,
`grant_type` VARCHAR(20) NOT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4;
Expand All @@ -320,7 +319,7 @@ DEFAULT CHARACTER SET = utf8mb4;
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `${schema}`.`client_grant_types` (
`grant_type_id` TINYINT(4) NOT NULL,
`client_id` VARCHAR(80) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NOT NULL,
`client_id` VARCHAR(80) NOT NULL,
INDEX `fk_oauth_client_grant_type_oauth_grant_type_idx` (`grant_type_id` ASC),
INDEX `fk_oauth_client_grant_type_oauth_client1_idx` (`client_id` ASC),
CONSTRAINT `fk_oauth_client_grant_type_oauth_client1`
Expand All @@ -338,7 +337,7 @@ DEFAULT CHARACTER SET = utf8mb4;
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `${schema}`.`comments` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`message` VARCHAR(1000) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NOT NULL,
`message` VARCHAR(1000) NOT NULL,
`feed_id` BIGINT(20) NOT NULL,
`reply_id` BIGINT(20) NULL DEFAULT NULL,
`like_count` BIGINT(20) NOT NULL,
Expand Down Expand Up @@ -382,7 +381,7 @@ CREATE TABLE IF NOT EXISTS `${schema}`.`comment_reports` (
`comment_id` BIGINT(20) NOT NULL,
`by` BIGINT(20) NOT NULL,
`report_type` TINYINT(4) NOT NULL,
`report_content` VARCHAR(1000) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NULL DEFAULT NULL,
`report_content` VARCHAR(1000) NULL DEFAULT NULL,
`reported_at` BIGINT(20) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE INDEX `UNIQUE` (`comment_id` ASC, `by` ASC),
Expand All @@ -403,11 +402,11 @@ DEFAULT CHARACTER SET = utf8mb4;
CREATE TABLE IF NOT EXISTS `${schema}`.`devices` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`account_id` BIGINT(20) NOT NULL,
`udid` VARCHAR(255) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NOT NULL,
`udid` VARCHAR(255) NOT NULL,
`device_type` TINYINT(4) NOT NULL,
`active_status` TINYINT(4) NOT NULL,
`push_token` VARCHAR(255) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NULL DEFAULT NULL,
`user_agent` VARCHAR(1000) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NULL DEFAULT NULL,
`push_token` VARCHAR(255) NULL DEFAULT NULL,
`user_agent` VARCHAR(1000) NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `fk_devices_accounts_idx` (`account_id` ASC, `udid` ASC),
CONSTRAINT `fk_devices_accounts1`
Expand Down Expand Up @@ -461,7 +460,7 @@ CREATE TABLE IF NOT EXISTS `${schema}`.`feed_reports` (
`feed_id` BIGINT(20) NOT NULL,
`by` BIGINT(20) NOT NULL,
`report_type` TINYINT(4) NOT NULL,
`report_content` VARCHAR(1000) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NULL DEFAULT NULL,
`report_content` VARCHAR(1000) NULL DEFAULT NULL,
`reported_at` BIGINT(20) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE INDEX `UNIQUE` (`by` ASC),
Expand All @@ -482,7 +481,7 @@ DEFAULT CHARACTER SET = utf8mb4;
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `${schema}`.`feed_tags` (
`feed_id` BIGINT(20) NOT NULL,
`name` VARCHAR(1024) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NOT NULL,
`name` VARCHAR(1024) NOT NULL,
`order_no` INT(11) NOT NULL,
INDEX `fk_feed_tags_feeds1_idx` (`feed_id` ASC),
CONSTRAINT `fk_feed_tags_feeds1`
Expand Down Expand Up @@ -635,7 +634,7 @@ CREATE TABLE IF NOT EXISTS `${schema}`.`group_reports` (
`group_id` BIGINT(20) NOT NULL,
`by` BIGINT(20) NOT NULL,
`report_type` TINYINT(4) NOT NULL,
`report_content` VARCHAR(1000) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NULL DEFAULT NULL,
`report_content` VARCHAR(1000) NULL DEFAULT NULL,
`reported_at` BIGINT(20) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE INDEX `UNIQUE` (`report_type` ASC, `by` ASC),
Expand Down Expand Up @@ -678,7 +677,7 @@ CREATE TABLE IF NOT EXISTS `${schema}`.`notifications` (
`by` BIGINT(20) NOT NULL,
`notification_type` BIGINT(20) NOT NULL,
`content_id` BIGINT(20) NULL DEFAULT NULL,
`url` VARCHAR(2083) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci' NOT NULL,
`url` VARCHAR(2083) NOT NULL,
`unread` TINYINT(4) NOT NULL,
`notified_at` BIGINT(20) NOT NULL,
PRIMARY KEY (`id`, `notification_type`),
Expand Down Expand Up @@ -744,6 +743,20 @@ CREATE TABLE IF NOT EXISTS `${schema}`.`relationships` (
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4;

-- -----------------------------------------------------
-- Table `${schema}`.`authentications`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `${schema}`.`authentications` (
`provider_id` VARCHAR(30) NOT NULL,
`provider_key` VARCHAR(255) NOT NULL,
`password` VARCHAR(255) NOT NULL,
`hasher` VARCHAR(30) NOT NULL,
`confirm` TINYINT(1) NOT NULL,
`account_id` BIGINT(20) NULL DEFAULT NULL,
PRIMARY KEY (`provider_id`, `provider_key`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4;


SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ trait BaseModules extends App {
def mobilePushModule: TwitterModule = DefaultMobilePushModule
def storageModule: TwitterModule = DefaultStorageModule
def deepLinkModule: TwitterModule = DefaultDeepLinkModule
def hashModule: TwitterModule = DefaultHashModule

addFrameworkModule(listenerModule)
addFrameworkModule(chatModule)
Expand All @@ -25,6 +24,5 @@ trait BaseModules extends App {
addFrameworkModule(storageModule)
addFrameworkModule(deepLinkModule)
addFrameworkModule(databaseModule)
addFrameworkModule(hashModule)

}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AccountsService @Inject()(
db: DatabaseService,
accountsRepository: AccountsRepository,
reportsRepository: ReportsRepository,
listenerService: ListenerService
listenerService: ListenerService,
) {

def find(sessionId: SessionId): Future[Account] = {
Expand All @@ -38,23 +38,23 @@ class AccountsService @Inject()(
accountsRepository.find(displayName, since, offset, count, sessionId)
}

def update(accountId: AccountId, displayName: Option[String], sessionId: SessionId): Future[Unit] = {
def updateDisplayName(accountId: AccountId, displayName: Option[String], sessionId: SessionId): Future[Unit] = {
accountsRepository.updateDisplayName(accountId, displayName, sessionId)
}

def update(accountName: String, sessionId: SessionId): Future[Unit] = {
def updateAccountName(accountName: String, sessionId: SessionId): Future[Unit] = {
for {
_ <- db.transaction(accountsRepository.updateAccountName(accountName, sessionId))
_ <- listenerService.accountNameUpdated(accountName, sessionId)
} yield (())
}

def update(displayName: String,
web: Option[String],
birthday: Option[Long],
location: Option[String],
bio: Option[String],
sessionId: SessionId): Future[Unit] = {
def updateProfile(displayName: String,
web: Option[String],
birthday: Option[Long],
location: Option[String],
bio: Option[String],
sessionId: SessionId): Future[Unit] = {

for {
_ <- db.transaction(accountsRepository.updateProfile(displayName, web, birthday, location, bio, sessionId))
Expand All @@ -77,13 +77,6 @@ class AccountsService @Inject()(
} yield (())
}

def update(oldPassword: String, newPassword: String, sessionId: SessionId): Future[Unit] = {
for {
_ <- db.transaction(accountsRepository.updatePassword(oldPassword, newPassword, sessionId))
_ <- listenerService.passwordUpdated(sessionId)
} yield (())
}

def findAccountStatus(accountId: AccountId, sessionId: SessionId): Future[AccountStatus] = {
accountsRepository.findActiveStatus(accountId, sessionId)
}
Expand Down

This file was deleted.

Loading

0 comments on commit e1e9364

Please sign in to comment.