Skip to content

Repository files navigation

Refresher

coverage style: very good analysis License: MIT

Generated by the Very Good CLI 🤖

A Very Good Project created by Very Good CLI.


Getting Started 🚀

This project contains 3 flavors:

  • development
  • staging
  • production

To run the desired flavor either use the launch configuration in VSCode/Android Studio or use the following commands:

# Development
$ flutter run --flavor development --target lib/main_development.dart

# Staging
$ flutter run --flavor staging --target lib/main_staging.dart

# Production
$ flutter run --flavor production --target lib/main_production.dart

*Refresher works on iOS, Android, Web, and Windows.


Running Tests 🧪

To run all unit and widget tests use the following command:

$ flutter test --coverage --test-randomize-ordering-seed random

To view the generated coverage report you can use lcov.

# Generate Coverage Report
$ genhtml coverage/lcov.info -o coverage/

# Open Coverage Report
$ open coverage/index.html

Working with Translations 🌐

This project relies on flutter_localizations and follows the official internationalization guide for Flutter.

Adding Strings

  1. To add a new localizable string, open the app_en.arb file at lib/l10n/arb/app_en.arb.
{
    "@@locale": "en",
    "counterAppBarTitle": "Counter",
    "@counterAppBarTitle": {
        "description": "Text shown in the AppBar of the Counter Page"
    }
}
  1. Then add a new key/value and description
{
    "@@locale": "en",
    "counterAppBarTitle": "Counter",
    "@counterAppBarTitle": {
        "description": "Text shown in the AppBar of the Counter Page"
    },
    "helloWorld": "Hello World",
    "@helloWorld": {
        "description": "Hello World Text"
    }
}
  1. Use the new string
import 'package:refresher/l10n/l10n.dart';

@override
Widget build(BuildContext context) {
  final l10n = context.l10n;
  return Text(l10n.helloWorld);
}

Adding Supported Locales

Update the CFBundleLocalizations array in the Info.plist at ios/Runner/Info.plist to include the new locale.

    ...

    <key>CFBundleLocalizations</key>
	<array>
		<string>en</string>
		<string>es</string>
	</array>

    ...

Adding Translations

  1. For each supported locale, add a new ARB file in lib/l10n/arb.
├── l10n
│   ├── arb
│   │   ├── app_en.arb
│   │   └── app_es.arb
  1. Add the translated strings to each .arb file:

app_en.arb

{
    "@@locale": "en",
    "counterAppBarTitle": "Counter",
    "@counterAppBarTitle": {
        "description": "Text shown in the AppBar of the Counter Page"
    }
}

app_es.arb

{
    "@@locale": "es",
    "counterAppBarTitle": "Contador",
    "@counterAppBarTitle": {
        "description": "Texto mostrado en la AppBar de la página del contador"
    }
}

Generating Translations

To use the latest translations changes, you will need to generate them:

  1. Generate localizations for the current project:
flutter gen-l10n --arb-dir="lib/l10n/arb"

Alternatively, run flutter run and code generation will take place automatically.

Notes

Meetup Wednesday Today’s Scope

  • Token Security

Knowing Flutter !== Knowing Mobile Development

Extras

  • HTTP Certificate Pinning

1: Set the token to expire after a set time so that a log-in is forced Useful for:

  • Where tight security isn’t required
  • Users de-activated elsewhere so when they are de-activated, they shouldn’t be able to access the app since the token is long living (Example: User deactivated on Google Admin, so their login won’t work, but they may have a valid token from the backend where the backend prefers to issue long-lasting tokens)

Steps

  • Log in
  • Go on the landing page
  • Open the debrief page

2: Refresh token Useful for:

  • Access Token

  • Refresh

  • More security-conscious APIs where instead of a user being forced to log back in to maintain the experience, they get two tokens, access token and a refresh token.

  • The access token is the token used to make the calls, then when it expires in the middle of a transaction to the target API, it’s refreshed and the request retried so that it doesn’t break the user flow

  • Call login endpoint (Username & Password)

  • Receive Access Token (To call the APIs) & Receive the Refresh Token (Longer lifespan)

  • Call your APIs normally,

  • At some point, the token expires (5 minutes, 10 minutes, 15 minutes, 1 request -> Token expired, refresh, then make next request)

  • At this point, you use your refresh token, to call an endpoint that will give you a new access token

  • Use the new token to make the request

Steps: (feature/setup-refresh-token)

  • Disable hive is logged out: lib/services/hive_service.dart
  • Enable error interceptor: lib/utils/network.dart
  • Enable dummy token expiration: lib/services/debrief_service.dart NB: Won’t need the error handlers for 401 in the individual methods

3: Auto log out Useful for:

  • Banks apps where you need to have the device request you to get signed out first
  • So banks are security sensitive
  • Slightly tedious to set-up, was unable to cover this in the sample app on time

Process

  • Wrap the app with Overlay (Portal)
  • Have a ticker to manage the time
  • When the time expires, use the overlay portal to show the prompt
  • Use Flutter to force an app restart, once it fails the check, then you have to log in again manually

https://pub.dev/packages/local_session_timeout

About

A demo of token security in mobile applications for the Wednesday Vibes meetup

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages