A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.amplify.aws/gen1/swift/build-a-backend/more-features/datastore/authz-rules-setup/ below:

Website Navigation


Set up authorization rules - Swift

Set up authorization rules

Amplify gives you the ability to limit which individuals or groups should have access to create, read, update, or delete data on your types by specifying an @auth directive.

Here's a high-level overview of the authorization scenarios we support in the Amplify libraries. Each scenario has options you can tune to fit the needs of your application.

DataStore only supports authorization rules specified on this page.

The links provided below to the CLI documentation for specific authorization rules only apply to those particular rules. Datastore only supports a subset of all possible authorization rules provided by the CLI. Therefore, the other authorization rules or setups described in the linked page do not apply to Datastore.

If your app uses authentication, it is recommended to call DataStore.clear() on sign-in or sign-out to remove any user-specific data. In scenarios where a mobile device can be shared by several users, calling DataStore.clear() will ensure that data does not leak from one user to another.

Commonly used @auth rule patterns Per User / Owner Based Data Access

The following are commonly used patterns for owner based authorization. For more information on how to fine tune these examples, please see the CLI documentation on owner based authorization.

The following are commonly used patterns for static group authorization. For more information on how to fine tune these examples, please see the CLI documentation on static group authorization.

Owner and Static Group Combined

The following are commonly used patterns for combining owner and static group authorization. For more information on how to fine tune these examples, please see the CLI documentation on static group authorization.

Public Data Access

The following are commonly used patterns to grant everyone access. For more information on how to fine tune these examples, please see the CLI documentation on public data access.

Signed-in User Data Access

The following are commonly used patterns for private authorization. For more information on how to fine tune these examples, please see the CLI documentation on signed-in user data access.

Owner based Authorization with OIDC provider

The following are commonly used patterns for owner based authorization using a 3rd party OIDC provider (e.g. Facebook, Google, etc...). For more information on how to fine tune these examples, please see the CLI documentation on using an oidc authorization provider.

When using a third-party OIDC auth provider, you are required to provide an instance of APIAuthProviderFactory. Your factory implementation must be capable of creating objects conforming to the AmplifyOIDCAuthProvider protocol. The responsibility of the AmplifyOIDCAuthProvider is to return the JWT token that was provided by your OIDC provider. To do this:

Static Group Authorization with OIDC provider

The following are commonly used patterns for using groupClaims to achieve group based authorization using a 3rd party OIDC provider. For more information on how to fine tune these examples, please see the CLI documentation on static group authorization.

Configure Multiple Authorization Types

For some use cases, you will want DataStore to use multiple authorization types. For example, an app might use API Key for public content and Cognito User Pool for personalized content once the user logs in.

By default, DataStore uses your API's default authorization type specified in the amplifyconfiguration.json/.dart/aws-exports.js file. Every network request sent through DataStore uses that authorization type, regardless of the model's @auth rule. To change the default authorization type, run amplify update api.

To enable DataStore to use multiple authorization types based on the model's @auth rules, run amplify update api to configure additional auth types and deploy by running amplify push. Then, configure the "auth mode strategy" when initializing DataStore:

In your App scene, configure Amplify in the initializer:

Add to your AppDelegate's application:didFinishLaunchingWithOptions method

This configuration enables DataStore to synchronize data using the model's @auth rule provider for each model.

Multiple authorization types priority order

If there are multiple @auth rules on a model, the rules will be ranked by priority (see below), and DataStore will attempt the synchronization with each authorization type until one succeeds (or they all fail).

If there is not an authenticated user session, DataStore will only attempt public rules.

If a model has no auth rules defined, DataStore will continue to use the default authorization type from amplifyconfiguration.json/.dart.

Example with multiple authorization types

DataStore will attempt to use owner-based authorization first when synchronizing data if there is an authenticated user. If that request fails for some reason, DataStore will attempt the request again with public authorization. If there is no authenticated user, public authorization will be used.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4