Skip to content

AppAuthHelper

Dan M edited this page Mar 29, 2022 · 2 revisions

AppAuthHelper contains methods related to logging in and out using flutter_appauth.


Tips and Tricks

You can set all of the parameters such as redirectUrl in static methods on the startup of your application, to save you passing them in later in your app:

void main() {

  runApp(const MyApp());
}
...

class _MyAppState extends State<MyApp> {
  ...

  @override
  void initState() {
    super.initState();
    ...

    AppAuthHelper.setRealm("realm");
    AppAuthHelper.setClientId("clientId");
    AppAuthHelper.setRedirectUrl("redirectUrl");
    AppAuthHelper.setAuthServerUrl("authServerUrl");
    ...
  }

API

Static Methods

static void disableColors()

Disables the colors for the static AppAuthHelper Log object.

static void setRedirectUrl(String redirectUrl)

Sets the url that the Auth Helper will redirect to after login. Should match the schema you used in your build files

static void setClientId(String clientId)

Sets the client id of the Auth Helper

static void setRealm(String realm)

Sets the keycloak realm used by the Auth Helper

static void setAuthServerUrl(String authServerUrl)

Sets the auth url used by the Auth Helper. For keycloak, should be like: https://keycloak.example.com/auth

static void setScopes(List<String> scopes)

Sets the scopes of the Auth Helper

static Future<bool> login({bool tokenLoop, String? redirectUrl, String? clientId, String? realm, String? authServerUrl})

Brings up the Auth Helper. If tokenLoop is true (It defaults to true), on successful login it will start a refresh token loop using Session.startTokenLoop. If the login is successful, will return true. You do not need to pass in the other parameters if they are set using the above setters.

static Future<bool> logout( {String? tokenId, String? redirectUrl, String? clientId, String? realm, String? authServerUrl})

Logs out the current user session. tokenId should be the Id Token of the token you are trying to log out.

static Future<TokenResponse?> refreshToken(String refreshToken, {String? redirectUrl, String? clientId, String? realm, String? authServerUrl})

Gets a new TokenResponse using a refresh token refreshToken. DON'T CALL THIS: unless you are manually handling your session data and not using Session.

Static Getters

static String get discoveryUrl

Returns the discovery url being used by the Auth Helper.

Clone this wiki locally