Skip to content

Commit

Permalink
Merge branch 'main' into dev/lubl/nav-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
nickrandolph authored Jun 2, 2023
2 parents 746ecfa + e39c283 commit 7a86628
Show file tree
Hide file tree
Showing 114 changed files with 1,978 additions and 684 deletions.
6 changes: 3 additions & 3 deletions build/ci/scripts/wasm-uitest-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ IFS=$'\n\t'

export UNO_UITEST_TARGETURI=http://localhost:5000
export UNO_UITEST_DRIVERPATH_CHROME=$BUILD_SOURCESDIRECTORY/build/node_modules/chromedriver/lib/chromedriver
export UNO_UITEST_CHROME_BINARY_PATH=$BUILD_SOURCESDIRECTORY/build/node_modules/puppeteer/.local-chromium/linux-800071/chrome-linux/chrome
export UNO_UITEST_CHROME_BINARY_PATH=$BUILD_SOURCESDIRECTORY/build/node_modules/puppeteer/.local-chromium/linux-991974/chrome-linux/chrome
export UNO_UITEST_SCREENSHOT_PATH=$BUILD_ARTIFACTSTAGINGDIRECTORY/screenshots/wasm
export BIN_LOG_PATH=$BUILD_ARTIFACTSTAGINGDIRECTORY/wasm-uitest.binlog
export UNO_UITEST_PLATFORM=Browser
Expand All @@ -28,8 +28,8 @@ dotnet run --project $UNO_UITEST_WASM_PROJECT -c Release --no-build &

cd $BUILD_SOURCESDIRECTORY/build

npm i chromedriver@86.0.0
npm i puppeteer@5.3.1
npm i chromedriver@102.0.0
npm i puppeteer@14.1.0
wget $UNO_UITEST_NUGET_URL
mono nuget.exe install NUnit.ConsoleRunner -Version $UNO_UITEST_NUNIT_VERSION

Expand Down
2 changes: 1 addition & 1 deletion doc/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ The generated solution will contain:

![The structure of the generated solution](./Overview/images/ProjectStructure-min.png)

#### 3. Running the Application
### 3. Running the Application

* Select a target from the drop-down as pictured below

Expand Down
13 changes: 5 additions & 8 deletions doc/Learn/Tutorials/Authentication/HowTo-Authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ uid: Learn.Tutorials.Authentication.HowToAuthentication

`Uno.Extensions.Authentication` provides you with a consistent way to add authentication to your application. It is recommended to use one of the built in `IAuthenticationService` implementations. This tutorial will use the custom authorization to validate user credentials.

> [!TIP]
> This guide assumes you used the Uno.Extensions template to create the solution. Instructions for creating an application from the template can be found [here](xref:Overview.Extensions).
## Step-by-steps

> [!IMPORTANT]
> This guide assumes you used the template wizard or `dotnet new unoapp` to create your solution. If not, it is recommended that you follow the [instructions](xref:Overview.Extensions) for creating an application from the template.
### 1. Basic Credential Checking

- Install `Uno.Extensions.Authentication` into all projects
Expand All @@ -31,11 +31,8 @@ uid: Learn.Tutorials.Authentication.HowToAuthentication
async (sp, dispatcher, tokenCache, credentials, cancellationToken) =>
{
var isValid = credentials.TryGetValue("Username", out var username) && username == "Bob";
if(isValid)
{
credentials;
}
return null;
return isValid ?
credentials : default;
})
));
});
Expand Down
85 changes: 81 additions & 4 deletions doc/Learn/Tutorials/Authentication/HowTo-Cookies.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,88 @@ uid: Learn.Tutorials.Authentication.HowToCookieAuthorization
---
# How-To: Using Cookies to Authorize

`Uno.Extensions.Authentication` provides you with a consistent way to add authentication to your application. It is recommended to use one of the built in `IAuthenticationService` implementations. This tutorial will use the custom authorization to validate user credentials.
Using **cookies** is a common way to store tokens that are needed to authenticate a user. When an HTTP request is successfully authenticated, the server will return a response that creates a cookie containing a token value. Uno Extensions makes these cookie-related authorization steps less tedious by doing the work of extracting these values and applying them to future requests. This tutorial will teach you how to configure authentication to apply tokens from a cookie when they are available.

> [!TIP]
> This guide assumes you used the Uno.Extensions template to create the solution. Instructions for creating an application from the template can be found [here](xref:Overview.Extensions).
> [!IMPORTANT]
> To follow these steps, you first need to have an authentication system set up. We recommend choosing one of the `IAuthenticationProvider` implementations provided by Uno Extensions. Cookie authorization can complement any of the tutorials such as [Get Started with Authentication](xref:Learn.Tutorials.Authentication.HowToAuthentication).
## Step-by-steps

### 1.
### 1. Enable cookies

- The first step is to opt-in to using cookies. This will allow for writing of returned access and refresh tokens to a cookie, and enables future reading of tokens from the cookie when they are available. You will also be able to name the tokens. Your app should already have an `IHostBuilder` configured to use an authentication provider like below:

```csharp
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
var builder = this.CreateBuilder(args)
.Configure(host =>
{
host.UseAuthentication(auth =>
auth.AddCustom(custom =>
custom.Login(
async (sp, dispatcher, tokenCache, credentials, cancellationToken) =>
{
var isValid = credentials.TryGetValue("Username", out var username) && username == "Bob";
return isValid ?
credentials : default;
})
));
});
...
```

- Modify the app to add the `Cookies()` extension method. Since the default HTTP request handler used does _not_ read tokens from cookies, this method will configure the `IAuthenticationBuilder` by registering a special handler that will parse the response for tokens and store them in a cookie. It will apply them to future requests.

```csharp
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
var builder = this.CreateBuilder(args)
.Configure(host =>
{
host.UseAuthentication(auth =>
auth.AddCustom(custom =>
custom.Login(
async (sp, dispatcher, tokenCache, credentials, cancellationToken) =>
{
var isValid = credentials.TryGetValue("Username", out var username) && username == "Bob";
return isValid ?
credentials : default;
})
),
configureAuthorization: builder =>
{
builder
.Cookies(/* options */);
});
});
...
```

### 2. Configure cookie options

- The `Cookies()` extension method takes two parameters; the first represents a name for the [access token](https://oauth.net/2/access-tokens/) cookie, and the second represents a name for the [refresh token](https://oauth.net/2/refresh-tokens/) cookie.
```csharp
configureAuthorization: builder =>
{
builder
.Cookies("AccessToken", "RefreshToken");
...
```

- Specifying a value for the latter is optional.

### 3. Authorize with a token value from a cookie

- With the appropriate handler enabled using the `Cookies()` extension method, attempts to authenticate with a provider will now try to authorize from a cookie. Access and refresh token information will be included in subsequent requests. If the cookie is not found, it will instead authenticate with the provider as normal.

- For more information on how to call the authentication service from a view model, see [Get Started with Authentication](xref:Learn.Tutorials.Authentication.HowToAuthentication).

## See also

- [Authentication](xref:Overview.Authentication)
- [Get Started with Authentication](xref:Learn.Tutorials.Authentication.HowToAuthentication)
- [What is a cookie?](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies)
- [Access tokens](https://oauth.net/2/access-tokens/)
- [Refresh tokens](https://oauth.net/2/refresh-tokens/)
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ uid: Learn.Tutorials.Authentication.HowToMsalAuthentication

`MsalAuthenticationProvider` allows your users to sign in using their Microsoft identities. It wraps the [MSAL library](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet) from Microsoft into an implementation of `IAuthenticationProvider` This tutorial will use MSAL authorization to validate user credentials.

> [!TIP]
> This guide assumes you used the Uno.Extensions template to create the solution. Instructions for creating an application from the template can be found [here](xref:Overview.Extensions).
## Step-by-steps

> [!IMPORTANT]
> This guide assumes you used the template wizard or `dotnet new unoapp` to create your solution. If not, it is recommended that you follow the [instructions](xref:Overview.Extensions) for creating an application from the template.
### 1. Prepare for MSAL authentication

- For this type of authentication, the application must be registered with the Microsoft identity platform. For more information, see [Register an application with the Microsoft identity platform](https://docs.microsoft.com/azure/active-directory/develop/quickstart-register-app).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ uid: Learn.Tutorials.Authentication.HowToOidcAuthentication

`OidcAuthenticationProvider` allows your users to sign in using their identities from a participating identity provider. It can wrap support for any [OpenID Connect](https://openid.net/connect/) backend, such as [IdentityServer](https://duendesoftware.com/products/identityserver) into an implementation of `IAuthenticationProvider`. This tutorial will use the OIDC authorization to validate user credentials.

> [!TIP]
> This guide assumes you used the Uno.Extensions template to create the solution. Instructions for creating an application from the template can be found [here](xref:Overview.Extensions).
## Step-by-steps

> [!IMPORTANT]
> This guide assumes you used the template wizard or `dotnet new unoapp` to create your solution. If not, it is recommended that you follow the [instructions](xref:Overview.Extensions) for creating an application from the template.
### 1. Prepare for OIDC authentication

- For this type of authentication, the application must already be registered with the desired identity provider.
Expand Down
6 changes: 3 additions & 3 deletions doc/Learn/Tutorials/Authentication/HowTo-WebAuthentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ uid: Learn.Tutorials.Authentication.HowToWebAuthentication

`WebAuthenticationProvider` provides an implementation that displays a web view in order for the user to login. After login, the web view redirects back to the application, along with any tokens. This tutorial will use web authorization to validate user credentials.

> [!TIP]
> This guide assumes you used the Uno.Extensions template to create the solution. Instructions for creating an application from the template can be found [here](xref:Overview.Extensions).
## Step-by-steps

> [!IMPORTANT]
> This guide assumes you used the template wizard or `dotnet new unoapp` to create your solution. If not, it is recommended that you follow the [instructions](xref:Overview.Extensions) for creating an application from the template.
### 1. Prepare for web authentication

- For this type of authentication, the application must already be registered with the desired identity provider.
Expand Down
67 changes: 37 additions & 30 deletions doc/Learn/Tutorials/Configuration/HowTo-Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,44 @@ uid: Learn.Tutorials.Configuration.HowToConfiguration

## Step-by-steps

> [!IMPORTANT]
> This guide assumes you used the template wizard or `dotnet new unoapp` to create your solution. If not, it is recommended that you follow the [instructions](xref:Overview.Extensions) for creating an application from the template.
### 1. Specify configuration information to load on `IConfigBuilder`

* Uno.Extensions apps specify which configuration information to load by calling the `UseConfiguration()` extension method for `IHostBuilder`.

* Use the `EmbeddedSource<T>()` extension method on `IConfigBuilder` to load configuration information from an assembly type you specify:

```csharp
public App()
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
Host = UnoHost
.CreateDefaultBuilder()
.UseConfiguration(configure: configBuilder =>
configBuilder
// Load configuration information from appsettings.json
.EmbeddedSource<App>()
)
var appBuilder = this.CreateBuilder(args)
.Configure(host => {
host.UseConfiguration(configure: configBuilder =>
configBuilder
// Load configuration information from appsettings.json
.EmbeddedSource<App>()
);
});
...
```

* By default, this method will extract values from an embedded resource (using the [EmbeddedResource](https://docs.microsoft.com/en-us/dotnet/api/system.codedom.compiler.compilerparameters.embeddedresources?view=dotnet-plat-ext-6.0#remarks) file build action) called `appsettings.json`, unless you optionally denote a different file name. The string you pass into the extension method will be concatenated in-between `appsettings` and its file extension. For instance, the following will also retrieve values from the file `appsettings.platform.json` embedded inside the `App` assembly:
```csharp
public App()
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
Host = UnoHost
.CreateDefaultBuilder()
.UseConfiguration(configure: configBuilder =>
configBuilder
.EmbeddedSource<App>()
// Load configuration information from appsettings.platform.json
.EmbeddedSource<App>("platform")
)
var appBuilder = this.CreateBuilder(args)
.Configure(host => {
host.UseConfiguration(configure: configBuilder =>
configBuilder
// Load configuration information from appsettings.json
.EmbeddedSource<App>()
// Load configuration information from appsettings.platform.json
.EmbeddedSource<App>("platform")
);
});
...
```

Expand All @@ -63,19 +69,20 @@ uid: Learn.Tutorials.Configuration.HowToConfiguration
* You can now use the `Section<T>()` extension method on `IConfigBuilder` to load configuration information for class or record of the type argument you specify:

```csharp
public App()
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
Host = UnoHost
.CreateDefaultBuilder()
.UseConfiguration(configure: configBuilder =>
configBuilder
// Load configuration information from appsettings.json
.EmbeddedSource<App>()
// Load configuration information from appsettings.platform.json
.EmbeddedSource<App>("platform")
// Load Auth configuration section
.Section<Auth>()
)
var appBuilder = this.CreateBuilder(args)
.Configure(host => {
host.UseConfiguration(configure: configBuilder =>
configBuilder
// Load configuration information from appsettings.json
.EmbeddedSource<App>()
// Load configuration information from appsettings.platform.json
.EmbeddedSource<App>("platform")
// Load configuration information for the Auth section
.Section<Auth>()
);
});
...
```

Expand All @@ -92,4 +99,4 @@ uid: Learn.Tutorials.Configuration.HowToConfiguration
{
var authSettings = settings.Value;
...
```
```
Loading

0 comments on commit 7a86628

Please sign in to comment.