Updated auth_oauth2

This commit is contained in:
thomashii 2021-07-10 09:29:41 +08:00
parent 88016ec045
commit f70f090e7b
3 changed files with 41 additions and 33 deletions

View file

@ -1,19 +1,31 @@
# 4.0.0 # Change Log
## 4.0.1
* Updated README
## 4.0.0
* Migrated to support Dart SDK 2.12.x NNBD * Migrated to support Dart SDK 2.12.x NNBD
# 3.0.0 ## 3.0.0
* Migrated to work with Dart SDK 2.12.x Non NNBD * Migrated to work with Dart SDK 2.12.x Non NNBD
# 2.1.0 ## 2.1.0
* Angel 2 + Dart 2 update * Angel 2 + Dart 2 update
* Support for handling errors + rejections. * Support for handling errors + rejections.
* Use `ExternalAuthOptions`. * Use `ExternalAuthOptions`.
# 2.0.0+1 ## 2.0.0+1
* Meta update to improve Pub score. * Meta update to improve Pub score.
# 2.0.0 ## 2.0.0
* Angel 2 + Dart 2 updates. * Angel 2 + Dart 2 updates.
# 1.0.2 ## 1.0.2
Added `getParameters` to `AngelOAuth2Options`.
Added `getParameters` to `AngelOAuth2Options`.

View file

@ -1,13 +1,15 @@
# angel3_auth_oauth2 # Angel3 OAuth2 Handler
[![version](https://img.shields.io/badge/pub-v4.0.0-brightgreen)](https://pub.dartlang.org/packages/angel3_auth_oauth2)
[![version](https://img.shields.io/badge/pub-v4.0.1-brightgreen)](https://pub.dartlang.org/packages/angel3_auth_oauth2)
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety) [![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion) [![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/auth_oauth2/LICENSE) [![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/auth_oauth2/LICENSE)
`package:angel3_auth` strategy for OAuth2 login, i.e. Facebook or Github. Angel3 library for authenticating users with remote identity providers via OAuth2, i.e. Facebook, Google, Azure AD, etc.
## Usage
# Usage
First, create an options object: First, create an options object:
```dart ```dart
@ -23,11 +25,10 @@ configureServer(Angel app) async {
} }
``` ```
After getting authenticated against the remote server, we need to be able to identify After getting authenticated against the remote server, we need to be able to identify users within our own application.
users within our own application.
```dart ```dart
typedef FutureOr<User> OAuth2Verifier(oauth2.Client, RequestContext, ResponseContext); typedef OAuth2Verifier = FutureOr<User> Function(oauth2.Client, RequestContext, ResponseContext);
/// You might use a pure function to create a verifier that queries a /// You might use a pure function to create a verifier that queries a
/// given service. /// given service.
@ -52,9 +53,7 @@ OAuth2Verifier oauth2verifier(Service<User> userService) {
} }
``` ```
Now, initialize an `OAuth2Strategy`, using the options and verifier. Now, initialize an `OAuth2Strategy`, using the options and verifier. You'll also need to provide a name for this instance of the strategy. Consider using the name of the remote authentication provider (ex. `facebook`).
You'll also need to provide a name for this instance of the strategy.
Consider using the name of the remote authentication provider (ex. `facebook`).
```dart ```dart
configureServer(Angel app) { configureServer(Angel app) {
@ -73,14 +72,12 @@ configureServer(Angel app) {
} }
``` ```
Lastly, connect it to an `AngelAuth` instance, and wire it up to an `Angel` server. Lastly, connect it to an `AngelAuth` instance, and wire it up to an `Angel` server. Set up two routes:
Set up two routes:
1. Redirect users to the external provider 1. Redirect users to the external provider
2. Acts as a callback and handles an access code 2. Acts as a callback and handles an access code
In the case of the callback route, you may want to display an HTML page that closes In the case of the callback route, you may want to display an HTML page that closes a popup window. In this case, use `confirmPopupAuthentication`, which is bundled with `package:angel3_auth`, as a `callback` function:
a popup window. In this case, use `confirmPopupAuthentication`, which is bundled with
`package:angel3_auth`, as a `callback` function:
```dart ```dart
configureServer(Angel app) async { configureServer(Angel app) async {
@ -103,9 +100,8 @@ configureServer(Angel app) async {
``` ```
## Custom Scope Delimiter ## Custom Scope Delimiter
This package should work out-of-the-box for most OAuth2 providers, such as Github or Dropbox.
However, if your OAuth2 scopes are separated by a delimiter other than the default (`' '`), This package should work out-of-the-box for most OAuth2 providers, such as Github or Dropbox. However, if your OAuth2 scopes are separated by a delimiter other than the default (`' '`), you can add it in the `OAuth2Strategy` constructor:
you can add it in the `OAuth2Strategy` constructor:
```dart ```dart
configureServer(Angel app) async { configureServer(Angel app) async {
@ -114,11 +110,10 @@ configureServer(Angel app) async {
``` ```
## Handling non-JSON responses ## Handling non-JSON responses
Many OAuth2 providers do not follow the specification, and do not return
`application/json` responses.
You can add a `getParameters` callback to parse the contents of any arbitrary Many OAuth2 providers do not follow the specification, and do not return `application/json` responses.
response:
You can add a `getParameters` callback to parse the contents of any arbitrary response:
```dart ```dart
OAuth2Strategy( OAuth2Strategy(
@ -133,4 +128,4 @@ OAuth2Strategy(
throw FormatException('Invalid content-type $contentType; expected application/x-www-form-urlencoded or application/json.'); throw FormatException('Invalid content-type $contentType; expected application/x-www-form-urlencoded or application/json.');
} }
); );
``` ```

View file

@ -1,7 +1,8 @@
name: angel3_auth_oauth2 name: angel3_auth_oauth2
version: 4.0.0 version: 4.0.1
description: angel_auth strategy for OAuth2 login, i.e. Facebook, Github, etc. description: Angel3 library for authenticating users with external identity providers via OAuth2.
homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/auth_oauth2 homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/angel3/packages/auth_oauth2
environment: environment:
sdk: '>=2.12.0 <3.0.0' sdk: '>=2.12.0 <3.0.0'
dependencies: dependencies: