0 purchases
dio oidc interceptor
Flutter OIDC Interceptor for Dio #
A Flutter Dio Interceptor for OpenID Connect (OIDC) authentication.
Getting Started #
Add package to your pubspec.yaml:
flutter pub add dio_oidc_interceptor
copied to clipboard
Usage #
import 'package:dio/dio.dart';
import 'package:dio_oidc_interceptor/dio_oidc_interceptor.dart';
void main() async {
final dio = Dio();
final interceptor = OidcInterceptor(
configuration: OpenIdConfiguration(
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
uri: 'https://your-oidc-provider.com',
scopes: ['openid', 'profile', 'email'],
));
dio.interceptors.add(interceptor);
await dio.login();
final response = await dio.get('https://api.example.com');
}
copied to clipboard
Use with Retrofit #
import 'package:dio/dio.dart';
import 'package:retrofit/retrofit.dart';
part 'backend_client.g.dart';
@RestApi(baseUrl: 'https://website/api/version/')
abstract class BackendClient {
factory BackendClient(Dio dio, {String baseUrl}) = _BackendClient;
}
class Backend {
late final Dio _dio;
late final BackendClient _backendClient;
final interceptor = OidcInterceptor(
configuration: OpenIdConfiguration(
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
uri: 'https://your-oidc-provider.com',
scopes: ['openid', 'profile', 'email'],
));
Backend(Authentication auth, Configuration configuration) {
_dio = Dio()..interceptors.add(interceptor);
_backendClient = BackendClient(_dio, baseUrl: 'https://website/api/version/');
}
Dio get dio => _dio;
BackendClient get backendClient => _backendClient;
}
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.