Firebase custom Auth with Microsoft Azure / Graph

I am building an enterprise application using Microsoft Graph to login. After a successful subscription, I want to use the token that will be sent for authentication in Firebase Auth (so that I can protect access to the database).

The token received after a successful login cannot be used directly in Firebase.

The Firebase user instructions page says:

Get the keys to your project:

  1. Go to the Service Accounts page in your project settings.
  2. Click Create a New Private Key at the bottom of the Firebase Admin SDK section on the Service Accounts page.
  3. A new pair of public and private keys of the service account is automatically saved on your computer. Copy this file to your authentication server.

The third paragraph says that you need to enter the key to the authentication server. Is this possible with Microsoft Graph or Azure AD ?

The key that Firebase gives you is the file JSON. I checked the Microsoft application registration portal, which allows you to edit the application manifest, but to no avail.

The file is JSONas follows:

{
    "type": "service_account",
    "project_id": "APP_ID",
    "private_key_id": "KEY_ID_VALUE",
    "private_key": "-----BEGIN PRIVATE KEY----<KEY VALUE>-----END PRIVATE KEY-----\n",
    "client_email": "firebase-adminsdk-0ubvc@********.iam.gserviceaccount.com",
    "client_id": "XXXXXXXXXXXX",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://accounts.google.com/o/oauth2/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-0ubvc%XXXXXXXX.iam.gserviceaccount.com"
}

I can't seem to find any github projects or stackoverflow threads that cover this issue.

How to get custom tokens using MS Graph or Azure AD?

+7
4

. , Stackoverflow, .

Firebase. Firebase Admin .

, :

1. Firebase Firebase. Firebase service-account.json. " " Firebase deploy

  1. index.js , :

    const admin = require('firebase-admin');
    
  2. :

    // Create a Firebase token from any UID
    exports.createFirebaseToken = functions.https.onRequest((req, res) => {
    
      // The UID and other things we'll assign to the user.
      const uid = req.body.uid;
      const additionalClaims = {
        name: req.body.name,
        email: req.body.email
      };
    
      // Create or update the user account.
      const userCreationTask = admin.auth().updateUser(uid, additionalClaims).catch(error => {
    
        if (req.method === 'PUT') {
          res.status(403).send('Forbidden!');
        }
    
        if (req.method === 'GET') {
         res.status(403).send('Please use POST for this function');
        }
    
        // If user does not exists we create it.
        if (error.code === 'auth/user-not-found') {
          console.log('Created user with UID:${uid}, Name: ${additionalClaims.name} and e-mail: ${additionalClaims.email}');
          return admin.auth().createUser({
          uid: uid,
          displayName: additionalClaims.name,
          email: additionalClaims.email,
        });
            }
            throw error;
            console.log('Error!');
        });
    
    
        return Promise.all([userCreationTask]).then(() => {
          console.log('Function create token triggered');
          // Create a Firebase custom auth token.
          admin.auth().createCustomToken(uid, additionalClaims).then((token) => {
          console.log('Created Custom token for UID "', uid, '" Token:', token);
            res.status(200).send(token);
            return token
        });
      });
    });
    

res.status . return . Firebase github.

  1. HTTP-, , Alamofire swift

    Alamofire.request("https://us-central1-<YOUR DATABASE REFERENCE>.cloudfunctions.net/createFirebaseToken", 
    method: .post, parameters: parameters, encoding: JSONEncoding.default).
    responseString(completionHandler: { (token) in
        // Handle the result here
    })
    

    Parameters - JSON , Firebase .

  2. ! , URL- , . , , . Firecast YouTube, Firebase, fooobar.com/questions/15676118/...

  3. , iOS Android, .

  4. Firebase, Microsoft

  5. , , ID Microsoft, ID Firebase.

+5

, , AAD IDP auth, JWT, Firebase. JWT , , firebase. , Java, , , Firebase Admin SDK. , , , , . -, , JWT, SDK Firebase Admin. JWT, , Firebase .

0

, . Microsoft Microsoft Microsoft . Firebase Firebase uid Microsoft. , Firebase Admin Node.js SDK:

admin.createCustomToken(msftUid, additionalUserClaims)
  .then(customToken => {
    // Return this to the client.
  })

, , signInWithCustomToken(customToken), Firebase Auth. currentUser.uid, Microsoft.

0

Source: https://habr.com/ru/post/1688592/


All Articles