패키지, 저장소 및 앱 카테고리 검색

패키지 상세v0.7.0

fresh

다트용 토큰 갱신 라이브러리입니다. 이 패키지는 REST, GraphQL 등 다양한 리프레시 토큰 구현에 공통되는 핵심 구성 요소를 노출합니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
8.7만
좋아요
157
Pub 점수
160

패키지 설치

flutter pub add fresh

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Fresh는 REST 및 GraphQL API에서 토큰 갱신 워크플로를 관리하기 위해 설계된 Dart 라이브러리입니다. 인증 토큰을 처리하기 위한 재사용 가능한 구성 요소를 제공하여 로직 중복 없이 안전하고 일관된 토큰 갱신을 보장합니다. 이 패키지는 토큰 만료 감지, 자동 갱신 요청, 오류 처리와 같은 일반적인 패턴을 추상화하여 Flutter 및 기타 Dart 애플리케이션에서 견고한 인증 흐름을 구현하는 것을 쉽게 만듭니다. 모듈성에 중점을 두어 모바일, 웹, 데스크톱 등 다양한 플랫폼을 지원합니다.

사용 사례

  • 만료된 JWT 토큰 처리
  • REST API에서 토큰 갱신 자동화
  • GraphQL 클라이언트에서 인증 상태 관리
  • 유효한 토큰으로 API 호출 보호
  • 유연한 인증 흐름 구현

주요 기능

  • 모듈러 토큰 갱신 아키텍처
  • REST 및 GraphQL 지원
  • 크로스 플랫폼 호환성
  • 실패한 요청에 대한 자동 재시도
  • 사용자 정의 가능한 갱신 전략

적합한 대상

  • API 인증이 있는 Flutter 앱
  • JWT 또는 유사 토큰을 사용하는 애플리케이션
  • 재사용 가능한 인증 시스템을 구축하는 개발자
  • 보안 토큰 관리가 필요한 프로젝트
  • 다중 플랫폼 애플리케이션

고려 사항

  • 특정 인증 엔드포인트를 위한 사용자 정의 구현이 필요합니다
  • dio 또는 http와 같은 HTTP 클라이언트와의 통합이 필요할 수 있습니다
  • 완전한 인증 솔루션이 아니지만 갱신 유틸리티입니다
  • 올바른 백엔드 토큰 갱신 설정에 따라 다름
  • 토큰 갱신에 국한됨—로그인 또는 로그아웃은 아님

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Fresh 🍋

build License: MIT GitHub stars


A collection of packages for automatic token refresh in Dart and Flutter. Fresh handles refreshing, caching, and attaching authentication tokens transparently so your API calls just work.

Why Fresh?

Token-based authentication seems simple until you handle the edge cases: tokens expire mid-session, multiple requests fail at the same time triggering duplicate refreshes, refresh tokens get revoked, and you need to route users to login when auth is lost. Fresh handles all of this so you don't have to.

  • No more manual 401 handling scattered across your codebase
  • No more race conditions when concurrent requests trigger simultaneous refreshes
  • No more stale tokens causing request failures - expired tokens are refreshed proactively before the request is even sent

Packages

Package Pub
fresh pub package
fresh_dio pub package
fresh_graphql pub package
fresh_http pub package

Features

  • Automatic token refresh on 401 / auth errors, with automatic request retry
  • Proactive refresh before requests when the token is expired
  • Single-flight refresh - concurrent requests share one refresh call instead of triggering multiple
  • authenticationStatus stream for reacting to login/logout events
  • Pluggable TokenStorage - bring your own persistence layer
  • Built-in OAuth2Token with expiresAt support

Usage

fresh_dio
final dio = Dio();

dio.interceptors.add(
  Fresh.oAuth2(
    tokenStorage: InMemoryTokenStorage<OAuth2Token>(),
    refreshToken: (token, client) async {
      final response = await client.post(
        'https://api.example.com/auth/refresh',
        data: {'refresh_token': token?.refreshToken},
      );
      return OAuth2Token(
        accessToken: response.data['access_token'],
        refreshToken: response.data['refresh_token'],
      );
    },
  ),
);

See the fresh_dio README for full documentation.

fresh_graphql
import 'dart:convert';

final freshLink = FreshLink.oAuth2(
  tokenStorage: InMemoryTokenStorage<OAuth2Token>(),
  refreshToken: (token, client) async {
    final response = await client.post(
      Uri.parse('https://api.example.com/auth/refresh'),
      body: jsonEncode({'refresh_token': token?.refreshToken}),
    );
    final body = jsonDecode(response.body) as Map<String, dynamic>;
    return OAuth2Token(
      accessToken: body['access_token'],
      refreshToken: body['refresh_token'],
    );
  },
  shouldRefresh: (response) =>
      response.errors?.any((e) => e.message.contains('UNAUTHENTICATED')) ?? false,
);

// HttpLink comes from package:gql_http_link
final link = Link.from([freshLink, HttpLink('https://api.example.com/graphql')]);

See the fresh_graphql README for full documentation.

fresh_http
import 'dart:convert';

final client = Fresh.oAuth2(
  tokenStorage: InMemoryTokenStorage<OAuth2Token>(),
  refreshToken: (token, client) async {
    final response = await client.post(
      Uri.parse('https://api.example.com/auth/refresh'),
      body: jsonEncode({'refresh_token': token?.refreshToken}),
    );
    final body = jsonDecode(response.body) as Map<String, dynamic>;
    return OAuth2Token(
      accessToken: body['access_token'],
      refreshToken: body['refresh_token'],
    );
  },
);

See the fresh_http README for full documentation.

카테고리

의존성

의존성 목록 1 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.

순위