Bird
Raised Fist0
Firebasecloud~20 mins

Custom authentication tokens in Firebase - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Firebase Custom Token Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediate
2:00remaining
What happens when a Firebase custom token expires?
You create a Firebase custom authentication token with a 1-hour expiration. What happens if a client tries to use this token after it expires?
AThe client is denied access and must request a new token to authenticate again.
BThe client can continue using the expired token without interruption.
CFirebase automatically refreshes the token without client intervention.
DThe client is permanently blocked from accessing Firebase services.
Attempts:
2 left
💡 Hint
Think about how tokens maintain security by limiting their valid time.
❓ Configuration
intermediate
2:00remaining
Which Firebase Admin SDK method creates a custom token?
You want to generate a custom authentication token for a user with ID 'user123'. Which Firebase Admin SDK method correctly creates this token?
Aadmin.auth().signInWithCustomToken('user123')
Badmin.auth().generateToken('user123')
Cadmin.auth().createCustomToken('user123')
Dadmin.auth().getCustomToken('user123')
Attempts:
2 left
💡 Hint
Look for the method that explicitly mentions 'create' and 'CustomToken'.
❓ security
advanced
2:00remaining
What is the best practice to secure the private key used for signing Firebase custom tokens?
You have a private key to sign Firebase custom tokens. Which practice best protects this key?
AStore the private key in a secure environment variable or secret manager, never in client code.
BEmbed the private key directly in the client app for faster token generation.
CShare the private key with all developers via email for easy access.
DCommit the private key to the public source code repository for transparency.
Attempts:
2 left
💡 Hint
Think about who should have access to sensitive keys and where they should be stored.
❓ Architecture
advanced
2:00remaining
How should you architect a system to issue Firebase custom tokens for users authenticated by an external system?
You have an external user database and want to allow those users to access Firebase services using custom tokens. What architecture best supports this?
AUse Firebase client SDK to create custom tokens without backend verification.
BAllow clients to generate custom tokens directly using the Firebase Admin SDK in the frontend.
CStore Firebase private keys in the external user database for token generation.
DCreate a secure backend service that verifies external user credentials and issues Firebase custom tokens on demand.
Attempts:
2 left
💡 Hint
Consider where sensitive operations like token signing should happen.
🧠 Conceptual
expert
2:00remaining
What is the main difference between Firebase custom tokens and ID tokens?
Firebase uses both custom tokens and ID tokens in authentication. What is the key difference between them?
AID tokens are created by your backend; custom tokens are issued by Firebase after sign-in.
BCustom tokens are short-lived tokens created by your backend to sign in users; ID tokens are issued by Firebase after sign-in and used to authorize requests.
CCustom tokens and ID tokens are the same and can be used interchangeably.
DID tokens are used only for anonymous users; custom tokens are for registered users.
Attempts:
2 left
💡 Hint
Think about who creates each token and when they are used.

Practice

(1/5)
1. What is the main purpose of Firebase custom authentication tokens?
easy
A. To store user data in Firebase Realtime Database
B. To sign in users from your own system to Firebase
C. To send notifications to users
D. To create Firebase projects automatically

Solution

  1. Step 1: Understand the role of custom tokens

    Custom tokens are used to authenticate users from an external system with Firebase.
  2. Step 2: Identify the correct purpose

    They allow users to sign in securely using tokens generated on your server.
  3. Final Answer:

    To sign in users from your own system to Firebase -> Option B
  4. Quick Check:

    Custom tokens = sign in users [OK]
Hint: Custom tokens = external user sign-in method [OK]
Common Mistakes:
  • Confusing tokens with data storage
  • Thinking tokens send notifications
  • Assuming tokens create projects
2. Which Firebase Admin SDK method is used to create a custom authentication token?
easy
A. admin.auth().createCustomToken(uid)
B. admin.database().createToken(uid)
C. firebase.auth().signInWithCustomToken(uid)
D. admin.storage().generateToken(uid)

Solution

  1. Step 1: Identify the correct Admin SDK service

    Custom tokens are created using the Authentication service, not database or storage.
  2. Step 2: Match the correct method

    The method to create a custom token is createCustomToken(uid) under admin.auth().
  3. Final Answer:

    admin.auth().createCustomToken(uid) -> Option A
  4. Quick Check:

    Custom token creation = admin.auth().createCustomToken [OK]
Hint: Use admin.auth().createCustomToken to generate tokens [OK]
Common Mistakes:
  • Using database or storage methods incorrectly
  • Confusing signInWithCustomToken with token creation
  • Calling methods on firebase instead of admin SDK
3. What will the following code output if uid is 'user123' and no errors occur?
const admin = require('firebase-admin');
admin.initializeApp();

admin.auth().createCustomToken('user123')
  .then(token => console.log(typeof token))
  .catch(error => console.error(error));
medium
A. 'object'
B. An error message
C. 'undefined'
D. 'string'

Solution

  1. Step 1: Understand createCustomToken return type

    The method returns a Promise that resolves to a string token.
  2. Step 2: Check console.log output

    Logging typeof token will print 'string' because the token is a string.
  3. Final Answer:

    'string' -> Option D
  4. Quick Check:

    createCustomToken returns string token [OK]
Hint: createCustomToken returns a string token inside a Promise [OK]
Common Mistakes:
  • Expecting an object instead of string
  • Confusing token with undefined
  • Assuming an error without cause
4. Identify the error in this code snippet for generating a custom token:
const admin = require('firebase-admin');

admin.auth().createCustomToken('12345')
  .then(token => console.log(token))
  .catch(error => console.error(error));
medium
A. Missing admin.initializeApp() call
B. Incorrect method name, should be generateCustomToken
C. createCustomToken does not return a Promise
D. UID must be a string, not a number

Solution

  1. Step 1: Check initialization of Firebase Admin SDK

    The admin SDK must be initialized with admin.initializeApp() before use.
  2. Step 2: Verify other parts

    The UID '12345' is a valid string, createCustomToken returns a Promise, and method name is correct.
  3. Final Answer:

    Missing admin.initializeApp() call -> Option A
  4. Quick Check:

    Initialize admin SDK before calling methods [OK]
Hint: Always call admin.initializeApp() before using admin SDK [OK]
Common Mistakes:
  • Passing number instead of string UID
  • Assuming createCustomToken is synchronous
  • Using wrong method name
5. You want to add extra user info like role: 'admin' in a custom token. Which code snippet correctly adds this claim?
hard
A. admin.auth().setCustomUserClaims(uid, { role: 'admin' })
B. admin.auth().createCustomToken(uid).setClaims({ role: 'admin' })
C. admin.auth().createCustomToken(uid, { role: 'admin' })
D. admin.auth().createCustomToken(uid, { claims: { role: 'admin' } })

Solution

  1. Step 1: Understand how to add extra claims in custom tokens

    The createCustomToken method accepts a second argument with additional claims as a plain object.
  2. Step 2: Evaluate each option

    admin.auth().createCustomToken(uid, { role: 'admin' }) correctly passes extra claims as second argument. admin.auth().createCustomToken(uid).setClaims({ role: 'admin' }) is invalid chaining. admin.auth().setCustomUserClaims(uid, { role: 'admin' }) sets claims on user but not in token creation. admin.auth().createCustomToken(uid, { claims: { role: 'admin' } }) nests claims incorrectly.
  3. Final Answer:

    admin.auth().createCustomToken(uid, { role: 'admin' }) -> Option C
  4. Quick Check:

    Extra claims go as second argument in createCustomToken [OK]
Hint: Pass extra claims as second argument to createCustomToken [OK]
Common Mistakes:
  • Trying to chain setClaims on token creation
  • Using setCustomUserClaims instead of token claims
  • Nesting claims inside another object
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard