mirror of
https://github.com/vran-dev/databasir.git
synced 2025-09-19 18:19:26 +08:00
feat: support github oauth
This commit is contained in:
10
dao/src/main/java/com/databasir/dao/enums/OAuthAppType.java
Normal file
10
dao/src/main/java/com/databasir/dao/enums/OAuthAppType.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.databasir.dao.enums;
|
||||
|
||||
public enum OAuthAppType {
|
||||
|
||||
GITHUB, GITLAB;
|
||||
|
||||
public boolean isSame(String type) {
|
||||
return this.name().equalsIgnoreCase(type);
|
||||
}
|
||||
}
|
@@ -1,22 +1,37 @@
|
||||
package com.databasir.dao.impl;
|
||||
|
||||
import com.databasir.dao.tables.OauthApp;
|
||||
import com.databasir.dao.exception.DataNotExistsException;
|
||||
import com.databasir.dao.tables.pojos.OauthAppPojo;
|
||||
import lombok.Getter;
|
||||
import org.jooq.DSLContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.databasir.dao.Tables.OAUTH_APP;
|
||||
|
||||
@Repository
|
||||
public class OAuthAppDao extends BaseDao<OauthApp> {
|
||||
public class OAuthAppDao extends BaseDao<OauthAppPojo> {
|
||||
|
||||
@Autowired
|
||||
@Getter
|
||||
private DSLContext dslContext;
|
||||
|
||||
public OAuthAppDao() {
|
||||
super(OAUTH_APP, OauthApp.class);
|
||||
super(OAUTH_APP, OauthAppPojo.class);
|
||||
}
|
||||
|
||||
public Optional<OauthAppPojo> selectOptionByRegistrationId(String registrationId) {
|
||||
return this.getDslContext()
|
||||
.select(OAUTH_APP.fields()).from(OAUTH_APP).where(OAUTH_APP.REGISTRATION_ID.eq(registrationId))
|
||||
.fetchOptionalInto(OauthAppPojo.class);
|
||||
}
|
||||
|
||||
public OauthAppPojo selectByRegistrationId(String registrationId) {
|
||||
return this.getDslContext()
|
||||
.select(OAUTH_APP.fields()).from(OAUTH_APP).where(OAUTH_APP.REGISTRATION_ID.eq(registrationId))
|
||||
.fetchOptionalInto(OauthAppPojo.class)
|
||||
.orElseThrow(() -> new DataNotExistsException("can not found oauth app by " + registrationId));
|
||||
}
|
||||
}
|
18
dao/src/main/resources/db/migration/V1.4__oauth.sql
Normal file
18
dao/src/main/resources/db/migration/V1.4__oauth.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
CREATE TABLE IF NOT EXISTS oauth_app
|
||||
(
|
||||
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
|
||||
registration_id VARCHAR(100) NOT NULL,
|
||||
app_name VARCHAR(128) NOT NULL,
|
||||
app_icon VARCHAR(256) NOT NULL DEFAULT '',
|
||||
app_type VARCHAR(64) NOT NULL COMMENT 'github, gitlab',
|
||||
client_id VARCHAR(256),
|
||||
client_secret VARCHAR(256),
|
||||
auth_url VARCHAR(256),
|
||||
resource_url VARCHAR(256),
|
||||
scope VARCHAR(256),
|
||||
update_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
create_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE uk_registration_id (registration_id)
|
||||
) CHARSET utf8mb4
|
||||
COLLATE utf8mb4_unicode_ci COMMENT 'oauth app info';
|
||||
|
Reference in New Issue
Block a user