Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/GitHub actions #22

Merged
merged 11 commits into from
Mar 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
blank_issues_enabled: false
contact_links:
- name: Report An Issue
url: https://github.com/gibahjoe/keycloak_flutter/issues
about: Please ask and answer questions here.
31 changes: 0 additions & 31 deletions .github/workflows/code_quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,6 @@ on:
workflow_dispatch:

jobs:
# dependency-review:
# name: Vulnerable dependencies 🔎
# runs-on: ubuntu-latest
# steps:
# - name: Checkout Repository
# uses: actions/checkout@v3.2.0
#
# - name: Scan
# uses: actions/dependency-review-action@v3.0.2

# lint:
# name: Lint 🔬
# runs-on: ubuntu-latest
#
# steps:
# - name: Checkout ⬇️
# uses: actions/checkout@v3.2.0
#
# - name: Setup node environment ⚙️
# uses: actions/setup-node@v3.5.1
# with:
# node-version: 16
# cache: 'npm'
# check-latest: true
#
# - name: Install dependencies 📦
# run: npm ci --no-audit
#
# - name: Run linter ✏️
# run: 'npm run lint:js && npm run lint:style'

build:
name: Build frontend 🛠️
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
- name: Checkout
uses: actions/checkout@v1
- name: Publish
uses: sakebook/actions-flutter-pub-publisher@v1.4.1
uses: sakebook/actions-flutter-pub-publisher@v1.3.1
with:
credential: ${{ secrets.PUB_CREDENTIAL_JSON }}
flutter_package: false
flutter_package: true
skip_test: true
dry_run: true
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [0.0.20] - 14/03/2020

- Added support for keycloak 20.0.3

## [0.0.19] - 14/03/2020

- Added support for keycloak 19.0.1
Expand Down
91 changes: 57 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Keycloak Flutter

[![pub package](https://img.shields.io/pub/v/keycloak_flutter.svg)](https://pub.dev/packages/keycloak_flutter)
[![Deploy 🏗️](https://github.com/gibahjoe/keycloak_flutter/actions/workflows/deploy.yml/badge.svg)](https://github.com/gibahjoe/keycloak_flutter/actions/workflows/deploy.yml)

> Easy Keycloak setup for Flutter applications.

Expand Down Expand Up @@ -94,12 +95,12 @@ A sample keycloak client is also included in the example codebase
```dart
late KeycloakService keycloakService;

void main() {
void main() async {
keycloakService = KeycloakService(KeycloakConfig(
url: 'http://localhost:8080', // Keycloak auth base url
realm: 'sample',
url: 'https://kc.devappliance.com', // Keycloak auth base url
realm: 'keycloak_flutter',
clientId: 'sample-flutter'));
keycloakService.init(
await keycloakService.init(
initOptions: KeycloakInitOptions(
onLoad: 'check-sso',
silentCheckSsoRedirectUri:
Expand All @@ -126,7 +127,6 @@ class MyApp extends StatelessWidget {

class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, this.title}) : super(key: key);

final String? title;

@override
Expand All @@ -144,22 +144,28 @@ class _MyHomePageState extends State<MyHomePage> {

@override
void initState() {
// TODO: implement initState
super.initState();
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
keycloakService.keycloakEventsStream.listen((event) async {
print(event);
if (event.type == KeycloakEventType.onAuthSuccess) {
_keycloakProfile = await keycloakService.loadUserProfile();
} else {
_keycloakProfile = null;
print('Registering postframe callback');
try {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
keycloakService.keycloakEventsStream.listen((event) async {
print(event);
if (event.type == KeycloakEventType.onAuthSuccess) {
_keycloakProfile = await keycloakService.loadUserProfile();
} else {
_keycloakProfile = null;
}
setState(() {});
});
if (keycloakService.authenticated) {
_keycloakProfile = await keycloakService.loadUserProfile(false);
}
setState(() {});
});
// if(keycloakService.authenticated){
// _keycloakProfile = await keycloakService.loadUserProfile(false);
// }
setState(() {});
});
} catch (e) {
print(e);
}
}

@override
Expand Down Expand Up @@ -194,32 +200,49 @@ class _MyHomePageState extends State<MyHomePage> {
.textTheme
.headline4,
),
ElevatedButton(
onPressed: () async {
print('refreshing token');
await keycloakService.updateToken(1000).then((value) {
print(value);
})
.catchError((onError) {
print(onError);
});
},
child: Text(
'Refresh token',
style: Theme
.of(context)
.textTheme
.headline4,
SizedBox(
height: 20,
),
if (_keycloakProfile?.username == null)
ElevatedButton(
onPressed: _login,
child: Text(
'Login',
style: Theme
.of(context)
.textTheme
.headline4,
),
),
SizedBox(
height: 20,
),
if (_keycloakProfile?.username != null)
ElevatedButton(
onPressed: () async {
print('refreshing token');
await keycloakService.updateToken(1000).then((value) {
print(value);
}).catchError((onError) {
print(onError);
});
},
child: Text(
'Refresh token',
style: Theme
.of(context)
.textTheme
.headline4,
),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _login,
tooltip: 'Login',
child: Icon(Icons.login),
),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
Expand Down
56 changes: 21 additions & 35 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import 'package:keycloak_flutter/keycloak_flutter.dart';

late KeycloakService keycloakService;

void main() {
void main() async {
keycloakService = KeycloakService(KeycloakConfig(
url: 'http://localhost:8080', // Keycloak auth base url
realm: 'sample',
url: 'https://kc.devappliance.com', // Keycloak auth base url
realm: 'keycloak_flutter',
clientId: 'sample-flutter'));
keycloakService.init(
await keycloakService.init(
initOptions: KeycloakInitOptions(
onLoad: 'check-sso',
silentCheckSsoRedirectUri:
Expand All @@ -28,15 +28,6 @@ class MyApp extends StatelessWidget {
title: 'Keycloak Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Keycloak demo'),
Expand All @@ -46,16 +37,6 @@ class MyApp extends StatelessWidget {

class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, this.title}) : super(key: key);

// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.

// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".

final String? title;

@override
Expand All @@ -75,21 +56,26 @@ class _MyHomePageState extends State<MyHomePage> {
void initState() {
// TODO: implement initState
super.initState();
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
keycloakService.keycloakEventsStream.listen((event) async {
print(event);
if (event.type == KeycloakEventType.onAuthSuccess) {
_keycloakProfile = await keycloakService.loadUserProfile();
} else {
_keycloakProfile = null;
print('Registering postframe callback');
try {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
keycloakService.keycloakEventsStream.listen((event) async {
print(event);
if (event.type == KeycloakEventType.onAuthSuccess) {
_keycloakProfile = await keycloakService.loadUserProfile();
} else {
_keycloakProfile = null;
}
setState(() {});
});
if (keycloakService.authenticated) {
_keycloakProfile = await keycloakService.loadUserProfile(false);
}
setState(() {});
});
// if(keycloakService.authenticated){
// _keycloakProfile = await keycloakService.loadUserProfile(false);
// }
setState(() {});
});
} catch (e) {
print(e);
}
}

@override
Expand Down
28 changes: 19 additions & 9 deletions lib/src/keycloak.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ abstract class KeycloakInitOptions {
/// adapter: MyCustomAdapter,
/// });
/// ```
external dynamic /*'default'|'cordova'|'cordova-native'|KeycloakAdapter*/ get adapter;
external dynamic /*'default'|'cordova'|'cordova-native'|KeycloakAdapter*/
get adapter;

external set adapter(
dynamic /*'default'|'cordova'|'cordova-native'|KeycloakAdapter*/ v);
Expand Down Expand Up @@ -346,10 +347,17 @@ abstract class KeycloakPromise<TSuccess, TError> {
@JS()
abstract class KeycloakError {
external String get error;

external set error(String v);
external String get error_description;
external set error_description(String v);
external factory KeycloakError({String error, String error_description});

@JS('error_description')
external String get errorDescription;

@JS('error_description')
external set errorDescription(String v);

external factory KeycloakError(
{String error, @JS('error_description') String errorDescription});
}

@anonymous
Expand Down Expand Up @@ -498,25 +506,31 @@ abstract class Keycloak {

/// The user id.
external String get subject;

external set subject(String v);

/// Response mode passed in init (default value is `'fragment'`).
external String /*'query'|'fragment'*/ get responseMode;

external set responseMode(String /*'query'|'fragment'*/ v);

/// Response type sent to Keycloak with login requests. This is determined
/// based on the flow value used during initialization, but can be overridden
/// by setting this value.
external String /*'code'|'id_token token'|'code id_token token'*/ get responseType;
external String /*'code'|'id_token token'|'code id_token token'*/
get responseType;

external set responseType(
String /*'code'|'id_token token'|'code id_token token'*/ v);

/// Flow passed in init.
external String /*'standard'|'implicit'|'hybrid'*/ get flow;

external set flow(String /*'standard'|'implicit'|'hybrid'*/ v);

/// The realm roles associated with the token.
external KeycloakRoles get realmAccess;

external set realmAccess(KeycloakRoles v);

/// The resource roles associated with the token.
Expand Down Expand Up @@ -686,7 +700,3 @@ abstract class Keycloak {
/// @private Undocumented.
external KeycloakPromise<dynamic /*{}*/, void> loadUserInfo();
}

/* WARNING: export assignment not yet supported. */

/// The 'Keycloak' namespace is deprecated, use named imports instead.
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: keycloak_flutter
description: Keycloak client adapter for flutter based on the keycloak-js implementation.
version: 0.0.19
version: 0.0.20
homepage: https://github.com/gibahjoe/keycloak_flutter

environment:
Expand Down
13 changes: 0 additions & 13 deletions test/keycloak_flutter_test.dart

This file was deleted.