Skip to content

Commit

Permalink
Merge pull request #56 from Bdaya-Dev/feat/auth-url-override
Browse files Browse the repository at this point in the history
feat: Discovery document override
  • Loading branch information
ahmednfwela authored Mar 1, 2024
2 parents 4e9fbac + b542c73 commit c907443
Show file tree
Hide file tree
Showing 32 changed files with 980 additions and 78 deletions.
52 changes: 52 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,58 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## 2024-03-01

### Changes

---

Packages with breaking changes:

- There are no breaking changes in this release.

Packages with other changes:

- [`oidc` - `v0.5.1`](#oidc---v051)
- [`oidc_core` - `v0.6.1`](#oidc_core---v061)
- [`oidc_default_store` - `v0.2.0+7`](#oidc_default_store---v0207)
- [`oidc_desktop` - `v0.2.0+7`](#oidc_desktop---v0207)
- [`oidc_android` - `v0.3.1+1`](#oidc_android---v0311)
- [`oidc_linux` - `v0.3.0+7`](#oidc_linux---v0307)
- [`oidc_flutter_appauth` - `v0.2.0+7`](#oidc_flutter_appauth---v0207)
- [`oidc_ios` - `v0.3.0+7`](#oidc_ios---v0307)
- [`oidc_macos` - `v0.3.0+7`](#oidc_macos---v0307)
- [`oidc_platform_interface` - `v0.3.1+1`](#oidc_platform_interface---v0311)
- [`oidc_web` - `v0.3.1+1`](#oidc_web---v0311)
- [`oidc_windows` - `v0.3.1+1`](#oidc_windows---v0311)

Packages with dependency updates only:

> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project.
- `oidc_default_store` - `v0.2.0+7`
- `oidc_desktop` - `v0.2.0+7`
- `oidc_android` - `v0.3.1+1`
- `oidc_linux` - `v0.3.0+7`
- `oidc_flutter_appauth` - `v0.2.0+7`
- `oidc_ios` - `v0.3.0+7`
- `oidc_macos` - `v0.3.0+7`
- `oidc_platform_interface` - `v0.3.1+1`
- `oidc_web` - `v0.3.1+1`
- `oidc_windows` - `v0.3.1+1`

---

#### `oidc` - `v0.5.1`

- **FEAT**: Support overriding the discovery document.
- **FEAT**: added `events` stream to `OidcUserManager`.

#### `oidc_core` - `v0.6.1`

- **FEAT**: Support overriding the discovery document.


## 2023-10-15

### Changes
Expand Down
39 changes: 37 additions & 2 deletions docs/oidc-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,11 @@ manager.events().listen((event) {
});
```

### OidcEvent
#### OidcEvent

The base class for all events, this contains an `at` property that stores when the event occurred.

### OidcPreLogoutEvent
#### OidcPreLogoutEvent

Occurs before a user is forgotten, either via `forgetUser()` or via `logout()`.

Expand All @@ -299,10 +299,45 @@ You can also override the refresh token `manager.refreshToken(overrideRefreshTok
It will either return `OidcUser` with the new token, `null` or throw an [OidcException].

`null` is returned in the following cases:

- The discovery document doesn't have `grant_types_supported` include `refresh_token`
- The current user is null.
- The current user's refresh token is null.

### Overriding the discovery document

There are cases where you want to change some properties in the retrieved discovery document, either permanently, or for a specific method.

e.g., you might want to have a register and a login button where the register button overrides the discovery document's `authorizationEndpoint` parameter, but the login button uses the idp provided value.

We use [package:copy_with_extension_gen](https://pub.dev/packages/copy_with_extension_gen) to generate `copyWith` extension methods to help consumers override specific parts of the `OidcProviderMetadata` discovery document.

#### Permanent override

You can do that via the `discoveryDocument` setter in `OidcUserManager`, e.g.

```dart
final userManager = OidcUserManager.lazy(/*...*/);
await userManager.init();
userManager.discoveryDocument = userManager.discoveryDocument.copyWith(/*...*/);
```

#### Per-method override

You can pass the `OidcProviderMetadata? discoveryDocumentOverride` parameter in some methods.

Example:

```dart
final userManager = OidcUserManager.lazy(/*...*/);
await userManager.init();
await userManager.loginAuthorizationCodeFlow(
discoveryDocumentOverride: userManager.discoveryDocument.copyWith(
authorizationEndpoint: "https://idp.com/register", //change to register url instead of login
)
);
```

### Dispose

If you aren't maintaining a single instance of the `OidcUserManager` class, you might want to `dispose()` it when you are done with the instance.
Expand Down
5 changes: 5 additions & 0 deletions packages/oidc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.5.1

- **FEAT**: Support overriding the discovery document.
- **FEAT**: added `events` stream to `OidcUserManager`.

## 0.5.0+1

- **DOCS**: added `sessionManagementSettings` to the wiki.
Expand Down
4 changes: 2 additions & 2 deletions packages/oidc/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ dependencies:
logging: ^1.2.0
oidc:
path: ../
oidc_core: ^0.6.0
oidc_default_store: ^0.2.0+6
oidc_core: ^0.6.1
oidc_default_store: ^0.2.0+7
url_strategy: ^0.2.0

dev_dependencies:
Expand Down
Loading

0 comments on commit c907443

Please sign in to comment.