-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
609 additions
and
37 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# OpenID Connect | ||
|
||
OIDC allow users to sign in with social logins or third party issuer. KitchenOwl supports three providers: Google, Apple (only on iOS & macOS), and a custom one. | ||
|
||
For self-hosted instances the custom provider is the most interesting one. | ||
|
||
### Setup | ||
Inside your OIDC you need to configure a new client, with the following to redirect URIs: | ||
|
||
<div class="annotate" markdown> | ||
- `FRONT_URL(1)/signin/redirect` | ||
- `kitchenowl:///signin/redirect` | ||
</div> | ||
|
||
1. FRONT_URL is the environment variable that exactly matches KitchenOwl's URL including the schema (e.g. `https://app.kitchenowl.org`) | ||
|
||
KitchenOwl will request the following scopes: | ||
|
||
- `openid` | ||
- `profile` | ||
- `email` | ||
|
||
You can then configure the backend using environment variables, just provide your issuer URL, client ID, and client secret: | ||
|
||
```yaml | ||
back: | ||
environment: | ||
- [...] | ||
- FRONT_URL=<URL> # front_url is requred when using oidc | ||
- OIDC_ISSUER=<URL> # e.g https://accounts.google.com | ||
- OIDC_CLIENT_ID=<ID> | ||
- OIDC_CLIENT_SECRET=<SECRET> | ||
``` | ||
If everything is set up correctly you should see a *sign in with OIDC* button at the bottom of the login page. | ||
![screenshot](/img/screenshots/oidc_button.png) | ||
### Linking accounts | ||
If you've already started using KitchenOwl or created an account first you can link an OIDC account to your existing KitchenOwl account. Just go to *settings* :material-arrow-right: Click on your profile at the top :material-arrow-right: *Linked Accounts* :material-arrow-right: and link your account. | ||
Account links are permanent and can only be removed by deleting the KitchenOwl account. Users that signed in using OIDC are normal users that, after setting a password, can also sing in using their username + password. Deleting a user from your OIDC authority will not delete a user from KitchenOwl. | ||
### Limitations | ||
Currently only Web, Android, iOS, and macOS are supported. | ||
### Apple & Google | ||
These two providers will allow anyone to sing in with an Apple or Google account. They can be configured similarly to custom providers but will show up with a branded sign in with button. | ||
It is not recommended setting up social logins for self-hosted versions as they might not work correctly. | ||
```yaml | ||
back: | ||
environment: | ||
- [...] | ||
- FRONT_URL=<URL> # front_url is requred when using oidc | ||
- APPLE_CLIENT_ID=<ID> | ||
- APPLE_CLIENT_SECRET=<SECRET> | ||
- GOOGLE_CLIENT_ID=<ID> | ||
- GOOGLE_CLIENT_SECRET=<SECRET> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:kitchenowl/cubits/auth_cubit.dart'; | ||
import 'package:kitchenowl/helpers/url_launcher.dart'; | ||
import 'package:kitchenowl/kitchenowl.dart'; | ||
import 'package:kitchenowl/services/api/api_service.dart'; | ||
import 'package:sign_in_with_apple/sign_in_with_apple.dart'; | ||
|
||
enum OIDCProivder { | ||
custom, | ||
google, | ||
apple; | ||
|
||
Widget toIcon(BuildContext context) { | ||
return const [ | ||
Icon(Icons.turn_slight_left_outlined), | ||
Image( | ||
image: AssetImage('assets/images/google_logo.png'), | ||
height: 32, | ||
), | ||
Icon(Icons.apple_rounded), | ||
][index]; | ||
} | ||
|
||
String toLocalizedString() { | ||
return const ["OIDC", "Google", "Apple"][index]; | ||
} | ||
|
||
@override | ||
String toString() { | ||
return name; | ||
} | ||
|
||
static OIDCProivder? parse(String str) { | ||
switch (str) { | ||
case 'custom': | ||
return OIDCProivder.custom; | ||
case 'google': | ||
return OIDCProivder.google; | ||
case 'apple': | ||
return OIDCProivder.apple; | ||
default: | ||
return null; | ||
} | ||
} | ||
|
||
Future<void> login(BuildContext context) async { | ||
if (this == OIDCProivder.apple) { | ||
final res = await ApiService.getInstance().getLoginOIDCUrl(toString()); | ||
if (res.$2 == null || res.$3 == null) return; | ||
try { | ||
final credential = await SignInWithApple.getAppleIDCredential( | ||
scopes: [ | ||
AppleIDAuthorizationScopes.email, | ||
AppleIDAuthorizationScopes.fullName, | ||
], | ||
state: res.$2, | ||
nonce: res.$3, | ||
); | ||
return BlocProvider.of<AuthCubit>(context).loginOIDC( | ||
credential.state!, | ||
credential.authorizationCode, | ||
(message) => showSnackbar( | ||
context: context, | ||
content: Text((message?.contains("DONE") ?? false) | ||
? AppLocalizations.of(context)!.done | ||
: AppLocalizations.of(context)!.error), | ||
width: null, | ||
), | ||
); | ||
} catch (_) { | ||
showSnackbar( | ||
context: context, | ||
content: Text(AppLocalizations.of(context)!.error), | ||
width: null, | ||
); | ||
} | ||
} else { | ||
final url = | ||
(await ApiService.getInstance().getLoginOIDCUrl(toString())).$1; | ||
if (url != null) return openUrl(context, url); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:intl/intl_standalone.dart'; | ||
// ignore: depend_on_referenced_packages | ||
import 'package:flutter_web_plugins/url_strategy.dart'; | ||
import 'app.dart'; | ||
|
||
Future main() async { | ||
WidgetsFlutterBinding.ensureInitialized(); | ||
usePathUrlStrategy(); | ||
if (!kIsWeb) await findSystemLocale(); //BUG in package for web? | ||
runApp(App()); | ||
} |
Oops, something went wrong.