MaikuB / MaikuB/flutter_appauth

i always get access_denied error while login in PROD Env only

Open
#621 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Objective-C
Stars
308
Forks
301
Avg merge
2d 11h
Merged PRs (30d)
5

Description

Hi,
my login process was working as expected in both env in our system
then suddenly without ant change in our side or backend side
i got this error

```
PlatformException(authorize_and_exchange_code_failed, Failed to authorize: access_denied, {code: -4, user_did_cancel: false, type: org.openid.appauth.oauth_authorization, error: access_denied, error_debug_description: Error Domain=org.openid.appauth.oauth_authorization Code=-4 "access_denied" UserInfo={OIDOAuthErrorResponseErrorKey={


error = "access_denied";


"session_state" = "78oZ27JfzCp8d9HZ26qJydWxRQKJ9-9F5Ol4hgaOwyo.9662F26EF4ED87A4878BD03BF12F731B";


state = "02M88KLFAZD4uZOwCbXbQs-QTv-OLxyG9JH-rLm3oL0";


}, NSLocalizedDescription=access_denied}}, null)
```
i don't know why this is happening
current config

```
ENVIRONMENT_NAME = PROD
AUTH_BASE_URL = https:///identitymanagementsts/
API_BASE_URL = https:///
AUTHORIZATION_END_POINT = connect/authorize
TOKEN_END_POINT = connect/token
END_SESSION_END_POINT = connect/endsession
CLIENT_ID = fa_app_prod02
REDIRECT_URL = .auth:/oauthredirect
POST_LOGOUT_REDIRECT_URL = .auth:/
SCOPES = [profile,phone,email,openid,fast_integration,skoruba_identity_admin_api,offline_access]
ISSUER = https:///identitymanagementsts/
GRANT_TYPE = refresh_token

```

DART CODE:

```
class AuthenticationService {
final FlutterAppAuth _appAuth = const FlutterAppAuth();

final String _clientId;
final String _redirectUrl;
final String _postLogoutRedirectUrl;
final AuthorizationServiceConfiguration _serviceConfig;
final String _issuer;
final String _grantType;
final List _scopes;

// Constructor
AuthenticationService({
required String clientId,
required String redirectUrl,
required String postLogoutRedirectUrl,
required AuthorizationServiceConfiguration serviceConfig,
required String issuer,
required String grantType,
required List scopes,
}) : _clientId = clientId,
_redirectUrl = redirectUrl,
_postLogoutRedirectUrl = postLogoutRedirectUrl,
_serviceConfig = serviceConfig,
_issuer = issuer,
_grantType = grantType,
_scopes = scopes;

/// Authorize the user and fetch tokens
Future> authorizeUser() async {
try {
final TokenResponse result = await _appAuth.authorizeAndExchangeCode(
AuthorizationTokenRequest(
_clientId,
_redirectUrl,
serviceConfiguration: _serviceConfig,
scopes: _scopes,
issuer: _issuer,
),
);

LogManager.instance.logToConsole(result.toString(),
title: "authorizeUser in service", illuminateLog: true);
return DataSuccess(result);
} catch (e) {
LogManager.instance.logToConsole(e.toString(),
title: "authorizeUser in service", illuminateLog: true);
return _handleAppAuthError(e);
}
}

/// Refresh the access token
Future> refreshToken(String refreshToken) async {
try {
final TokenResponse result = await _appAuth.token(
TokenRequest(
_clientId,
_redirectUrl,
refreshToken: refreshToken,
serviceConfiguration: _serviceConfig,
scopes: _scopes,
issuer: _issuer,
grantType: _grantType,
),
);

return DataSuccess(result);
} catch (e) {
return _handleAppAuthError(e);
}
}

/// Logout the user by clearing tokens
Future> logout(String idTokenKey) async {
try {
await _appAuth.endSession(EndSessionRequest(
idTokenHint: idTokenKey,
postLogoutRedirectUrl: _postLogoutRedirectUrl,
serviceConfiguration: _serviceConfig,
));
return DataSuccess(NullParam());
} catch (e) {
return _handleAppAuthError(e);
}
}

DataState _handleAppAuthError(Object e) {
if (e is FlutterAppAuthUserCancelledException) {
return DataFailed(AuthenticationError.userCancelled.toString());
} else if (e is FlutterAppAuthPlatformException) {
return DataFailed(AuthenticationError.platformException.toString());
} else if (e is PlatformException) {
return DataFailed(AuthenticationError.platformException.toString());
} else {
return DataFailed(AuthenticationError.unknown.toString());
}
}
}

enum AuthenticationError { userCancelled, platformException, unknown }

```

Contributor guide

Open the contributing guide

Research direction

Start with AuthenticationService.authorizeUser and its AuthorizationTokenRequest, then inspect the supplied PROD endpoints, client ID, redirect URL, issuer, and scopes. Compare the PROD configuration with the working environment and AppAuth's authorization flow; done means identifying a reproducible cause for access_denied or documenting the missing information needed to isolate it.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
authentication, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.