0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Vibe Coding2日目

Last updated at Posted at 2025-06-05

はじめに

  • 昨日書いた記事の続きで、労働保険年度更新APIをVibeCodingで作成していく
  • 今日は認証など

システムの前提

  • Api,Service,Dao,Entityという構成

動機

  • create文を書いて、Entityを書いて、Daoを書いて、Serviceを書いてと勧めるのだが、Entityを書いた後に、ふとVibeCodingでいけるんじゃないか?と思った

作業の流れ

  • アクセストークンを保持するテーブルを作成して登録処理までを作成する
  1. SQL作成
create table egov_api_token(
id bigint auto_increment,
inserted varchar(256) not null,
insert_datetime timestamp not null,
updated varchar(256),
update_datetime timestamp,
update_seq integer,
access_token varchar(128),
expires_in timestamp,
refresh_expires_in timestamp,
refresh_token	varchar(128),
token_type varchar(6),
id_token varchar(128),
not_before_policy timestamp,
session_state varchar(128),
scope	varchar(32),
primary key(id)
);
  1. Entity作成
@IQTable(name = "egov_api_token", inheritColumns = true)
public class EgovApiToken extends AbstractTable {

  /** アクセストークン. */
  @IQColumn(length = 32, nullable = false)
  public String access_token;
  
  /** アクセストークンの有効期限. */
  @IQColumn(length = 128, nullable = false)
  public LocalDateTime expires_in;
  
  /** リフレッシュトークンの有効期限. */
  @IQColumn(length = 128, nullable = false)
  public LocalDateTime refresh_expires_in;

  /** リフレッシュトークン. */
  @IQColumn(length = 128, nullable = false)
  public String refresh_token;

  /** トークンタイプ. */
  @IQColumn(length = 6, nullable = false)
  public String token_type;

  /** IDトークン. */
  @IQColumn(length = 128, nullable = false)
  public String id_token;

  /** アクセスが有効となる日時. */
  @IQColumn(length = 128, nullable = false)
  public String not_before_policy;

  /** セッション状態を表す識別子. */
  @IQColumn(length = 128, nullable = false)
  public String session_state;

  /** ユーザ認可リクエストで指定したscope. */
  @IQColumn(length = 128, nullable = false)
  public String scope;

  public EgovApiToken() {}
}

Vibe Coding

  1. Chatで「EgovApiTokenのDaoを作って」を実行
public class EgovApiTokenDao {

    private final Db db;

    public EgovApiTokenDao(Db db) {
        this.db = db;
    }

    public void insert(EgovApiToken token) {
        db.insert(token);
    }

    public void update(EgovApiToken token) {
        db.update(token);
    }

    public void delete(EgovApiToken token) {
        db.delete(token);
    }

    public EgovApiToken findByAccessToken(String accessToken) {
        EgovApiToken t = new EgovApiToken();
        return db.from(t).where(t.access_token).is(accessToken).selectFirst();
    }

    public List<EgovApiToken> findAll() {
        EgovApiToken t = new EgovApiToken();
        return db.from(t).select();
    }
}

これは、欲しい結果と全然違う。。

  1. 参考にするファイル等を開いてあげてChatで「BankApiTokenDao.javaを参考にEgovApiToken.javaのEgovApiTokenDao.javaを作って」を実行
/**
 * {@link EgovApiToken}DAO.
 *
 * @author uchicom
 */
public class EgovApiTokenDao extends AbstractDao<EgovApiToken> {

    /** コンストラクタ. */
    public EgovApiTokenDao(DbHelper<EgovApiToken> helper) {
        super(helper);
    }

    public EgovApiToken findLatest(LocalDateTime now) {
        var egovApiToken = new EgovApiToken();
        return helper.from(egovApiToken).where(egovApiToken.expires_in).atLeast(now).selectFirst();
    }
}

求めた結果になりました。

  1. 反映を押下するとファイルを新規作成してくれました。

所感

  • コピペで作業していた部分を、お願いすることはできる。
  • 作業速度としては、コピペして名前だけ変更するほうが早い。
  • AIの得意不得意を試しながら見つけていく感覚。

開発メモ

  • e-Govの認証認可方式の絵がわかりずらかったので、ここにメモする。
  • WEBシステムだと、登場人物は利用者ブラウザ、WEBシステム、電子申請システムとなる

WEBシステム認証認可フロー

  1. ブラウザで電子申請システムの認証用URLにアクセス
  2. 電子申請システムで認証する
  3. リダイレクトされてWEBシステムが表示される
  4. WEBシステム側では、リダイレクト時にクエリパラメータで受けった情報を電子申請システムに連携して認可コードをもらう
  5. WEBシステムは認可コードを電子申請システムに連携してアクセストークンをもらう

トークンの制限時間

  • 認可コードタイムアウト:60秒
  • リフレッシュトークン有効期限:180日
  • アクセストークン有効期限:1時間
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?