Simple Auth는 앱과 API용 사용자 인증을 간소화하기 위해 설계된 가벼운 Flutter 패키지입니다. 로그인 흐름, 토큰 관리 및 여러 플랫폼 간 세션 지속성을 처리하기 위한 간단하고 일관된 인터페이스를 제공합니다. 통합의 용이성을 고려하여 OAuth2, JWT 및 사용자 정의 로그인 워크플로우와 같은 일반적인 인증 방법을 지원합니다. 복잡한 구현 세부 사항을 추상화하여 봐일러플레이트 코드 없이 최소한의 효과적인 인증 솔루션을 원하는 개발자에게 이상적입니다.
사용 사례
OAuth2로 사용자 로그인
API 토큰 관리
세션 지속성
사용자 정의 인증 흐름
크로스 플랫폼 인증
빠른 프로토타이핑
주요 기능
최소 설정
여러 인증 유형을 지원합니다
크로스 플랫폼 호환성
토큰 저장 유틸리티
클린 API 설계
내장 세션 처리
적합한 대상
초보자 플러터 개발자
기본 인증이 필요한 앱
빠른 앱 개발
다중 플랫폼 프로젝트
단순성을 우선시하는 팀
고려 사항
제한된 고급 기능
기업 규모의 인증에 적합하지 않습니다
내장된 UI 컴포넌트 없음
외부 인증 공급자에 의존합니다
저수준 로직에 대한 통제가 적음
간단한 사용 사례에만 최적
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Most apps need to make API calls. Every API needs authentication, yet no developer wants to deal with authentication. Simple Auth embeds authentication into the API so you dont need to deal with it.
And of course any standard OAuth2/Basic Auth server.
Usage
var api = new simpleAuth.GoogleApi(
"google", "client_id",clientSecret: "clientSecret",
scopes: [
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/userinfo.profile"
]);
var request = newRequest(HttpMethod.Get, "https://www.googleapis.com/oauth2/v1/userinfo?alt=json");
var userInfo = await api.send<UserInfo, UserInfo>(request);
That's it! If the user is not logged in, they will automatically be prompted. If their credentials are cached from a previous session, the api call proceeds! Expired tokens even automatically refresh.
Flutter Setup
Call SimpleAuthFlutter.init(); in your Main.Dart. Now Simple Auth can automatically present your login UI
Redirect
Google requires the following redirect: com.googleusercontent.apps.YOUR_CLIENT_ID
Simple Auth by default uses SFSafari on iOS and Chrome Tabs on Android.
This means normal http redirects cannot work. You will need to register a custom scheme for your app as a redirect. For most providers, you can create whatever you want. i.e. com.myapp.foo:/redirct
Android Manifest
you would then add the following to your Android manifest
Note, if you want to avoid Apples mandatory user consent dialog
"foo" Wants to use "bar.com" to Sign In
This allows the app and website to share information about you.
add the lines above and set FooAuthenticator.useSSO = false; which will not use SFAuthenticationSession on iOS, and ASWebAuthenticationSession on macOS. This is the default behavior for the Keycloak provider.
Serialization
Json objects will automatically serialize if you conform to JsonSerializable
If you use the generator and you objects have the factory factory JsonSerializable.fromJson(Map<String, dynamic> json) your api calls will automatically Serialize/Deserialize
Or you can pass your own Converter to the api and handle conversion yourself.