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

패키지 상세v0.4.10+2

openid_client

OpenID Connect를 사용하고 클라이언트를 구현하기 위한 라이브러리입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
1.6만
좋아요
105
Pub 점수
150

패키지 설치

flutter pub add openid_client

패키지 개요

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

OpenID Connect 클라이언트를 구현하기 위한 Flutter/Dart 패키지로, 신뢰할 수 있는 인증을 위해 아이덴티티 공급자와 통합할 수 있습니다. OAuth 2.0 흐름, 토큰 관리 및 잘 알려진 엔드포인트를 통한 제공자 구성 발견을 지원합니다. Google, Auth0 또는 사용자 정의 ID 공급자와의 통합을 간소화하며, PKCE를 사용한 인가 코드 흐름을 포함한 복잡한 인증 워크플로우를 처리합니다. 크로스 플랫폼 사용을 위해 설계되어 Android, iOS, Web, macOS, Windows, Linux에서 원활하게 작동합니다. 표준화되고 안전한 사용자 인증이 필요한 앱에 적합합니다.

사용 사례

  • OpenID Connect 신원 공급자와의 통합
  • 모바일 및 웹 앱에서 안전한 로그인 흐름 구현
  • OAuth 2.0 토큰 및 세션 관리
  • 단일 로그인(SSO) 시나리오 지원
  • 외부 신원 제공자와 함께 인증된 플러터 애플리케이션 빌드

주요 기능

  • OpenID Connect 및 OAuth 2.0 흐름을 지원합니다
  • 공급자 구성의 자동 탐지
  • 강화된 보안을 위한 PKCE 지원
  • 크로스 플랫폼 호환성
  • 토큰 저장 및 새로 고침 처리
  • 잘 문서화된 API 및 예제

적합한 대상

  • 외부 인증을 사용하여 안전한 Flutter 앱을 개발하는 개발자
  • OpenID Connect 공급자 사용 팀
  • SSO 또는 연합 신원이 필요한 앱
  • 강력한 토큰 수명 주기 관리가 필요한 프로젝트

고려 사항

  • OpenID Connect 개념에 대한 이해가 필요합니다
  • 신원 공급자 설정을 올바르게 구성해야 합니다
  • 사용자 지정 도메인 또는 범위에 대해 추가 설정이 필요할 수 있습니다
  • 서버 측 인증에 직접적으로 사용하기에는 적합하지 않습니다

원본 README

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

Ceasefire Now

:heart: sponsor

openid_client

Build Status

Library for working with OpenID Connect and implementing clients.

It currently supports these features:

  • discover OpenID Provider metadata
  • parsing and validating id tokens
  • basic tools for implementing implicit and authorization code flow
  • authentication for command line tools
  • RP initiated logout

Besides authentication providers that support OpenID Connect, this library can also work with other authentication providers supporting oauth2, like Facebook. For these providers, some features (e.g. discovery and id tokens) will not work. You should define the metadata for those providers manually, except for Facebook, which is predefined in the library.

Usage

Below are some examples of how to use the library. For more examples, see the example folder. It contains full examples of how to use the library with a keycloak server in a flutter, command line and browser application.

A simple usage example:

import 'package:openid_client/openid_client.dart';

main() async {

  // print a list of known issuers
  print(Issuer.knownIssuers);

  // discover the metadata of the google OP
  var issuer = await Issuer.discover(Issuer.google);
  
  // create a client
  var client = new Client(issuer, "client_id", "client_secret");
  
  // create a credential object from authorization code
  var c = client.createCredential(code: "some received authorization code");

  // or from an access token
  c = client.createCredential(accessToken: "some received access token");

  // or from an id token
  c = client.createCredential(idToken: "some id token");      

  // get userinfo
  var info = await c.getUserInfo();
  print(info.name);
  
  // get claims from id token if present
  print(c.idToken?.claims?.name);
  
  // create an implicit authentication flow
  var f = new Flow.implicit(client);
  
  // or an explicit flow
  f = new Flow.authorizationCode(client);
  
  // set the redirect uri
  f.redirectUri = Uri.parse("http://localhost");
  
  // do something with the authentication url
  print(f.authenticationUrl);
  
  // handle the result and get a credential object
  c = await f.callback({
    "code": "some code",
  });
  
  // validate an id token
  var violations = await c.validateToken();
}

Usage example on flutter
// import the io version
import 'package:openid_client/openid_client_io.dart';
// use url launcher package 
import 'package:url_launcher/url_launcher.dart';

authenticate(Uri uri, String clientId, List<String> scopes) async {   
    
    // create the client
    var issuer = await Issuer.discover(uri);
    var client = new Client(issuer, clientId);
    
    // create a function to open a browser with an url
    urlLauncher(String url) async {
        if (await canLaunch(url)) {
          await launch(url, forceWebView: true);
        } else {
          throw 'Could not launch $url';
        }
    }
    
    // create an authenticator
    var authenticator = new Authenticator(client,
        scopes: scopes,
        port: 4000, urlLancher: urlLauncher);
    
    // starts the authentication
    var c = await authenticator.authorize();
    
    // close the webview when finished
    closeWebView();
    
    // return the user info
    return await c.getUserInfo();

}
Usage example on command line
// import the io version
import 'package:openid_client/openid_client_io.dart';

authenticate(Uri uri, String clientId, List<String> scopes) async {   
    
    // create the client
    var issuer = await Issuer.discover(uri);
    var client = new Client(issuer, clientId);
    
    // create an authenticator
    var authenticator = new Authenticator(client,
        scopes: scopes,
        port: 4000);
    
    // starts the authentication
    var c = await authenticator.authorize(); // this will open a browser
    
    // return the user info
    return await c.getUserInfo();
}
Usage example in browser
// import the browser version
import 'package:openid_client/openid_client_browser.dart';

authenticate(Uri uri, String clientId, List<String> scopes) async {   
    
    // create the client
    var issuer = await Issuer.discover(uri);
    var client = new Client(issuer, clientId);
    
    // create an authenticator
    var authenticator = new Authenticator(client, scopes: scopes);
    
    // get the credential
    var c = await authenticator.credential;
    
    if (c==null) {
      // starts the authentication
      authenticator.authorize(); // this will redirect the browser
    } else {
      // return the user info
      return await c.getUserInfo();
    }
}

Command line tool

Install
pub global activate openid_client
Usage

Show a list of known OpenID providers:

openid_client issuers list

Discover and show the metadata of an OP:

openid_client issusers discover https://www.example.com

Show a list of known clients:

openid_client clients list

Add a client:

openid_client clients configure --secret optional_secret https://some.issuer.com client_id

Remove a client:

openid_client clients remove https://some.issuer.com client_id

Authenticate with a client:

openid_client clients auth --secret optional_secret https://some.issuer.com client_id

Show the content of an id token and validate it:

openid_client tokens validate eyJhbGciOiJSUzI1NiIsImtpZCI6ImE2YzJjNmQ0ZTZkYTFmOWJjMTdmYzhkMzExMzNiOTJmMDdlOTgxMTkifQ.eyJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLCJpYXQiOjE0ODU4ODQyNzcsImV4cCI6MTQ4NTg4Nzg3NywiYXRfaGFzaCI6Ik9nWUlZRzM1WXB6RmVvRlZBeWd1VUEiLCJhdWQiOiI1ODExNTUxMDQ5NDMtcnBqazBzanZucDFrZ2FkYzV0Mm5pOXFvYWt0ZGpzMjEuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJzdWIiOiIxMTI2NzgyNTk2NzYyMTE3MDcxNDgiLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwiYXpwIjoiNTgxMTU1MTA0OTQzLXJwamswc2p2bnAxa2dhZGM1dDJuaTlxb2FrdGRqczIxLmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29tIiwiZW1haWwiOiJyaWsuYmVsbGVuc0BnbWFpbC5jb20iLCJuYW1lIjoiUmlrIEJlbGxlbnMiLCJwaWN0dXJlIjoiaHR0cHM6Ly9saDUuZ29vZ2xldXNlcmNvbnRlbnQuY29tLy1lRmpwUXFfUTZWUS9BQUFBQUFBQUFBSS9BQUFBQUFBQUFCUS9md1U0alVicTJ5US9zOTYtYy9waG90by5qcGciLCJnaXZlbl9uYW1lIjoiUmlrIiwiZmFtaWx5X25hbWUiOiJCZWxsZW5zIiwibG9jYWxlIjoibmwifQ.TlXzuNLdd5hX-bzMrwBaclcE8z4So2wFJAZ_H7hGz8YA4lCxHV8iON8yuJ1PdXGuOOkDXScj4qSPK80IZ_J29Uf2azCH83djpjyP4McB_dG4zXkUSFGFTHiNnqmvFbMmL-91A74teAr1ZHDx5-so2bHs16_c8immj2YM5GqlN4FG_IFCqRZ-7jEn9m_SjBXpb_NahiDB-bk47npmM9GIWq4OhV4e4tpFO1XY7H4fDHoiBhkc1nrbUjiqTH3VOJVQNp6FjiO2ErR7UWWnSKX6PMFDJ-U-QSsC8gu0PtuIa1ZUXvTAdX5vKt_fsKijbiT0xUUq8xJATaDh8-aBsNKpqQ

Features and bugs

Please file feature requests and bugs at the issue tracker.

Sponsor

Creating and maintaining this package takes a lot of time. If you like the result, please consider to :heart: sponsor. With your support, I will be able to further improve and support this project. Also, check out my other dart packages at pub.dev.

카테고리

의존성

의존성 목록 8 개

소스 저장소

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