Skip to content

Repository files navigation

日本語 | 简体中文 | Deutsch | Français | 한국어

misskey_auth

Demo

License

A Flutter library for authenticating with Misskey servers. It supports both OAuth 2.0 and MiAuth, and stores tokens for multiple accounts.

Features

  • OAuth 2.0 authentication for Misskey servers (v2023.9.0 and later)
  • MiAuth authentication for older servers
  • Authentication in the external browser (no embedded WebView)
  • PKCE (Proof Key for Code Exchange)
  • Callbacks to the app through a custom URL scheme
  • Secure token storage using flutter_secure_storage
  • Token storage for multiple accounts and switching the active account
  • MisskeyAuthManager, a high-level API that runs the flows and saves tokens
  • iOS, Android, and macOS

Requirements

  • Flutter 3.47.1 or later, and Dart 3.13.1 or later (before Dart 4)
  • Android API 24 or later, with compileSdk 37 or later
  • iOS 15 or later
  • macOS 12.0 or later

If you are upgrading from an earlier version, read Upgrading first. On Android, users must sign in again.

Installation

dependencies:
  misskey_auth: ^0.2.0-beta.2

Quick Start

import 'package:misskey_auth/misskey_auth.dart';

final auth = MisskeyAuthManager.defaultInstance();

// OAuth (Misskey v2023.9.0 and later)
final oauthKey = await auth.loginWithOAuth(
  MisskeyOAuthConfig(
    host: 'misskey.io',
    clientId: 'https://yourpage/yourapp/',
    redirectUri: 'yourscheme://oauth/callback',
    scope: 'read:account write:notes',
    callbackScheme: 'yourscheme',
  ),
  setActive: true,
);

// MiAuth (also works on older servers)
final miKey = await auth.loginWithMiAuth(
  MisskeyMiAuthConfig(
    host: 'misskey.io',
    appName: 'Your App',
    callbackScheme: 'yourscheme',
    permissions: ['read:account', 'write:notes'],
  ),
  setActive: true,
);

// Read the saved token of the active account
final current = await auth.currentToken();

Before this code works, you need two things:

  1. A client_id page (OAuth only). Publish an HTTPS page that lists your redirect_uri in <link rel="redirect_uri">. See client_id Page.
  2. A custom URL scheme registered in your app. Add yourscheme to Info.plist on iOS and to CallbackActivity of flutter_web_auth_2 on Android. macOS needs no registration, but it needs entitlements for network access and the keychain. See Platform Setup.

Documentation

License

This project is published by 司書 (LibraryLibrarian) under the 3-Clause BSD License. See LICENSE.

About

Flutter-based Misskey authentication library

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages