InfosysMobile DeveloperAuthentication & Authorization

As an Infosys Mobile Developer, how would you design a secure and scalable authentication and authorization framework for a new enterprise mobile application, integrating with existing identity providers and ensuring data protection?

Infosys Mobile Developer 3–5 Years Authentication & Authorization

7 min readUpdated

Designing a secure and scalable authentication and authorization framework for an enterprise mobile application involves several layers, focusing on robust identity management, secure communication, and flexible access control. The core approach typically leverages industry standards like OAuth 2.0 and OpenID Connect (OIDC) for authentication, integrating with existing enterprise identity providers (IdPs) such as Azure AD or Okta. For authorization, a combination of Role-Based Access Control (RBAC) and Attribute-Based Access Control (ABAC) is effective, enforced both client-side (for UI rendering) and server-side (for critical resource access).

Core Authentication Flow

The mobile application would initiate an authorization code flow with Proof Key for Code Exchange (PKCE) against the enterprise’s OIDC-compliant IdP. This redirects the user to the IdP’s login page, either via a secure web view or a browser. Upon successful authentication, the IdP issues an authorization code, which the mobile client exchanges for an ID Token (for user identity) and an Access Token (for API access) at the IdP’s token endpoint. Refresh Tokens, if allowed by policy and securely stored, enable silent token renewal without re-prompting the user. All token exchanges must occur over HTTPS, and client secrets should never be embedded in the mobile application.

Secure Token Management and Data Protection

Access Tokens should be short-lived to minimize the impact of compromise. They are typically stored in memory or a secure, encrypted storage mechanism provided by the OS (e.g., iOS Keychain, Android Keystore), protected by biometrics where possible. Refresh Tokens, if used, must be long-lived, stored in the most secure local storage available, and invalidated on logout or suspicious activity. Sensitive user data obtained post-authentication should be encrypted at rest on the device and transmitted over TLS. Data synchronization with backend services must also employ strong authorization checks to prevent unauthorized data access or modification.

Best practice

Always use the Authorization Code Flow with PKCE for mobile clients. This prevents interception of the authorization code by malicious applications. Implement server-side token validation for every API request using the Access Token, ensuring the token is valid, unexpired, and scopes match the requested resource. Employ strong cryptographic practices for any sensitive data stored locally. Regularly rotate API keys and certificates, and implement a robust logging and monitoring strategy for authentication events to detect anomalies.

Edge case interviewers probe for

Interviewers might ask about handling offline authentication or authorization. For authentication, one strategy is to cache the ID Token payload locally and validate its expiration. For authorization, policies can be cached, allowing the app to initially render UIs based on cached permissions, but critical actions always require server-side re-validation. Another edge case is handling token revocation, where a compromised token needs immediate invalidation across all user sessions and devices.

Common mistake

A common mistake is embedding client secrets directly into the mobile application, which makes them vulnerable to reverse engineering. Another is relying solely on client-side authorization for UI elements, failing to implement strict server-side authorization checks for all critical API endpoints. Improper storage of Refresh Tokens, such as in unencrypted SharedPreferences or UserDefaults, also represents a significant security flaw, allowing attackers persistent access.

What the interviewer is checking

The interviewer is evaluating your understanding of secure mobile development practices, familiarity with industry-standard protocols like OAuth 2.0 and OIDC, and ability to integrate with enterprise identity solutions. They look for practical knowledge of secure storage, token lifecycle management, handling of offline scenarios, and a layered approach to authorization that includes both client-side and server-side enforcement. Demonstrating an awareness of common vulnerabilities and mitigation strategies is crucial.

Imagine you are entering a very exclusive club, which is the enterprise application, and there is a strict bouncer at the door, which is the identity provider. Instead of showing your ID directly to everyone inside, the bouncer checks your ID, gives you a special wristband (the Access Token) that changes color frequently, and maybe a secret membership card (the Refresh Token) if you are a regular. Every time you want to order a drink or go to a VIP area, the staff (APIs) just quickly check your wristband’s current color, not your actual ID, because it is faster and safer.

Your phone is like your wallet, holding these special wristbands and membership cards. When you log in, your phone securely asks the bouncer for new credentials. If you are offline, your wallet might remember the last valid wristband color, so you can still look at the menu, but you cannot actually order a drink until the staff can check your new wristband color with the bouncer. This way, your real ID is never exposed, and if someone snatches your wallet, those wristbands expire quickly, making them useless to an unauthorized person.

Why interviewers ask this

Interviewers ask this to gauge your understanding of fundamental security principles in mobile development and your ability to apply industry-standard protocols. It assesses your practical knowledge of securing data, managing user sessions, and integrating with complex enterprise IT landscapes, which is crucial for building reliable and trustworthy applications.

What a strong answer signals

A strong answer signals deep knowledge of OAuth 2.0 and OIDC, especially the PKCE flow. It demonstrates an understanding of secure token storage, refresh mechanisms, and comprehensive server-side authorization. You should articulate strategies for handling edge cases like offline access and token revocation, highlighting a security-first mindset and attention to detail.

Common follow-ups

  • How would you handle user session management and inactivity timeouts?
  • What are the risks of using Refresh Tokens and how do you mitigate them?
  • Explain the difference between OAuth 2.0 and OpenID Connect.

Advanced variation

Design a system that supports step-up authentication for sensitive transactions within the mobile application, integrating with a multi-factor authentication (MFA) provider. Discuss how this affects the token issuance and validation process, and the user experience for such a flow.

Consider an enterprise mobile banking application where users need to securely access their accounts and perform transactions. Initially, a naive approach might store user credentials or long-lived tokens directly in unencrypted local storage. A more robust solution involves using OAuth 2.0 with PKCE for initial login, securing Access Tokens in the platform’s secure enclave (Keychain/Keystore) for short-term API access, and storing Refresh Tokens (if needed) with biometric protection. All sensitive API calls are then authorized by valid Access Tokens, and the backend verifies these tokens with the IdP, ensuring that even if a device is compromised, the window for unauthorized access is minimized and critical data remains protected.

AuthService.kt (Android Example)

class AuthService(
    private val authStateManager: AuthStateManager,
    private val authService: AuthorizationService
) {
    fun performAuthRequest(activity: Activity) {
        val serviceConfig = AuthorizationServiceConfiguration(
            Uri.parse("https://idp.infosys.com/oauth2/authorize"),
            Uri.parse("https://idp.infosys.com/oauth2/token")
        )

        val authRequest = AuthorizationRequest.Builder(
            serviceConfig,
            "your_client_id",
            ResponseTypeValues.CODE,
            Uri.parse("com.infosys.app:/oauth2redirect")
        )
        .setScope("openid profile email")
        .setPrompt("login")
        .build()

        val authIntent = authService.getAuthorizationRequestIntent(authRequest)
        activity.startActivityForResult(authIntent, REQUEST_CODE_AUTH)
    }

    fun handleAuthResponse(data: Intent?) {
        val response = AuthorizationResponse.fromIntent(data)
        val ex = AuthorizationException.fromIntent(data)

        authStateManager.updateAfterAuthorization(response, ex)
        if (response != null && ex == null) {
            val tokenRequest = response.createTokenExchangeRequest()
            authService.performTokenRequest(
                tokenRequest,
                object : AuthorizationService.TokenResponseCallback {
                    override fun onTokenRequestCompleted(
                        tokenResponse: TokenResponse?,
                        tokenException: AuthorizationException?
                    ) {
                        authStateManager.updateAfterTokenResponse(tokenResponse, tokenException)
                        if (tokenResponse != null) {
                            // Tokens successfully exchanged and stored securely
                            val accessToken = tokenResponse.accessToken
                            val refreshToken = tokenResponse.refreshToken
                            // Use tokens for API calls
                        }
                    }
                }
            )
        }
    }
}
                
Mobile App Identity Provider Backend APIs Auth Request (PKCE) Tokens (ID, Access, Refresh) API Calls (with Access Token)
  1. 1Always use Authorization Code Flow with PKCE for mobile apps to prevent code interception.
  2. 2Store Access Tokens in secure memory or platform-specific secure storage, making them short-lived.
  3. 3Implement robust server-side authorization checks for all API calls, never relying solely on client-side controls.
  4. 4Integrate with existing enterprise identity providers (IdPs) using OIDC for streamlined user management.
  5. 5Design for offline capabilities by caching necessary authorization policies locally with proper invalidation strategies.