জাভাস্ক্রিপ্ট দিয়ে অ্যাপল ব্যবহার করে প্রমাণীকরণ করুন

এন্ড-টু-এন্ড OAuth 2.0 সাইন-ইন ফ্লো চালানোর জন্য আপনি Firebase SDK ব্যবহার করে আপনার ব্যবহারকারীদের তাদের Apple ID ব্যবহার করে Firebase-এর সাথে প্রমাণীকরণ করতে দিতে পারেন।

আপনি শুরু করার আগে

Apple ব্যবহার করে ব্যবহারকারীদের সাইন ইন করতে, প্রথমে Apple এর বিকাশকারী সাইটে Apple এর সাথে সাইন ইন কনফিগার করুন, তারপর আপনার Firebase প্রকল্পের জন্য একটি সাইন-ইন প্রদানকারী হিসাবে Apple সক্ষম করুন৷

অ্যাপল ডেভেলপার প্রোগ্রামে যোগ দিন

Apple এর সাথে সাইন ইন শুধুমাত্র Apple বিকাশকারী প্রোগ্রামের সদস্যদের দ্বারা কনফিগার করা যেতে পারে৷

অ্যাপল দিয়ে সাইন ইন কনফিগার করুন

On the Apple Developer site, do the following:

  1. ওয়েবের জন্য Apple এর সাথে কনফিগার সাইন ইনের প্রথম বিভাগে বর্ণিত হিসাবে আপনার অ্যাপের সাথে আপনার ওয়েবসাইট যুক্ত করুন৷ অনুরোধ করা হলে, একটি রিটার্ন ইউআরএল হিসাবে নিম্নলিখিত URL নিবন্ধন করুন:

    https://YOUR_FIREBASE_PROJECT_ID.firebaseapp.com/__/auth/handler

    আপনি Firebase কনসোল সেটিংস পৃষ্ঠায় আপনার Firebase প্রকল্প আইডি পেতে পারেন।

    আপনার হয়ে গেলে, আপনার নতুন পরিষেবা আইডি নোট করুন, যা আপনাকে পরবর্তী বিভাগে প্রয়োজন হবে৷

  2. অ্যাপল ব্যক্তিগত কী দিয়ে একটি সাইন ইন তৈরি করুন । পরবর্তী বিভাগে আপনার নতুন ব্যক্তিগত কী এবং কী আইডির প্রয়োজন হবে৷
  3. If you use any of Firebase Authentication 's features that send emails to users, including email link sign-in, email address verification, account change revocation, and others, configure the Apple private email relay service and register noreply@ YOUR_FIREBASE_PROJECT_ID .firebaseapp.com (or your customized email template domain) so Apple can relay emails sent by Firebase Authentication বেনামী অ্যাপল ইমেল ঠিকানায়.

একটি সাইন-ইন প্রদানকারী হিসাবে Apple সক্ষম করুন৷

  1. আপনার প্রকল্পে Firebase যোগ করুন
  2. Firebase কনসোলে , Auth বিভাগটি খুলুন। সাইন ইন পদ্ধতি ট্যাবে, অ্যাপল প্রদানকারী সক্ষম করুন। পূর্ববর্তী বিভাগে আপনি যে পরিষেবা আইডি তৈরি করেছেন তা উল্লেখ করুন। এছাড়াও, OAuth কোড ফ্লো কনফিগারেশন বিভাগে , আপনার Apple টিম আইডি এবং পূর্ববর্তী বিভাগে আপনার তৈরি করা ব্যক্তিগত কী এবং কী আইডি উল্লেখ করুন।

অ্যাপল বেনামী ডেটা প্রয়োজনীয়তা মেনে চলুন

অ্যাপলের সাথে সাইন ইন ব্যবহারকারীদের সাইন ইন করার সময় তাদের ইমেল ঠিকানা সহ তাদের ডেটা বেনামী করার বিকল্প দেয়৷ যে ব্যবহারকারীরা এই বিকল্পটি বেছে নেন তাদের কাছে privaterelay.appleid.com ডোমেনের ইমেল ঠিকানা রয়েছে৷ আপনি যখন আপনার অ্যাপে Apple এর সাথে সাইন ইন ব্যবহার করেন, তখন আপনাকে অবশ্যই এই বেনামী Apple ID সংক্রান্ত যেকোন প্রযোজ্য বিকাশকারী নীতি বা Apple থেকে শর্তাবলী মেনে চলতে হবে।

আপনি একটি বেনামী অ্যাপল আইডির সাথে সরাসরি সনাক্তকারী ব্যক্তিগত তথ্য সংযুক্ত করার আগে যেকোন প্রয়োজনীয় ব্যবহারকারীর সম্মতি প্রাপ্ত করা এর মধ্যে রয়েছে। ফায়ারবেস প্রমাণীকরণ ব্যবহার করার সময়, এতে নিম্নলিখিত ক্রিয়াগুলি অন্তর্ভুক্ত থাকতে পারে:

  • একটি বেনামী অ্যাপল আইডি বা বিপরীতে একটি ইমেল ঠিকানা লিঙ্ক করুন.
  • একটি বেনামী অ্যাপল আইডিতে একটি ফোন নম্বর লিঙ্ক করুন বা এর বিপরীতে
  • একটি বেনামী সামাজিক শংসাপত্র (ফেসবুক, গুগল, ইত্যাদি) একটি বেনামী অ্যাপল আইডিতে বা এর বিপরীতে লিঙ্ক করুন৷

উপরের তালিকাটি সম্পূর্ণ নয়। আপনার অ্যাপ অ্যাপলের প্রয়োজনীয়তা পূরণ করছে তা নিশ্চিত করতে আপনার ডেভেলপার অ্যাকাউন্টের সদস্যপদ বিভাগে অ্যাপল ডেভেলপার প্রোগ্রাম লাইসেন্স চুক্তি পড়ুন।

Firebase SDK দিয়ে সাইন-ইন ফ্লো পরিচালনা করুন

আপনি যদি একটি ওয়েব অ্যাপ তৈরি করেন, তাহলে আপনার ব্যবহারকারীদের Firebase-এর মাধ্যমে তাদের Apple অ্যাকাউন্ট ব্যবহার করে প্রমাণীকরণ করার সবচেয়ে সহজ উপায় হল Firebase JavaScript SDK-এর মাধ্যমে সম্পূর্ণ সাইন-ইন প্রবাহ পরিচালনা করা।

Firebase JavaScript SDK দিয়ে সাইন-ইন প্রবাহ পরিচালনা করতে, এই ধাপগুলি অনুসরণ করুন:

  1. সংশ্লিষ্ট প্রদানকারী আইডি apple.com ব্যবহার করে একটি OAuthProvider- এর একটি উদাহরণ তৈরি করুন।

    Web

    import { OAuthProvider } from "firebase/auth";
    
    const provider = new OAuthProvider('apple.com');

    Web

    var provider = new firebase.auth.OAuthProvider('apple.com');
  2. ঐচ্ছিক: ডিফল্টের বাইরে অতিরিক্ত OAuth 2.0 স্কোপ নির্দিষ্ট করুন যা আপনি প্রমাণীকরণ প্রদানকারীর কাছ থেকে অনুরোধ করতে চান।

    Web

    provider.addScope('email');
    provider.addScope('name');

    Web

    provider.addScope('email');
    provider.addScope('name');

    By default, when One account per email address is enabled, Firebase requests email and name scopes. আপনি যদি এই সেটিংটি প্রতি ইমেল ঠিকানায় একাধিক অ্যাকাউন্টে পরিবর্তন করেন, তাহলে Firebase অ্যাপল থেকে কোনো সুযোগের অনুরোধ করে না যদি না আপনি সেগুলি নির্দিষ্ট করেন।

  3. ঐচ্ছিক: আপনি যদি ইংরেজি ছাড়া অন্য কোনো ভাষায় Apple-এর সাইন-ইন স্ক্রীন প্রদর্শন করতে চান, তাহলে locale প্যারামিটার সেট করুন। সমর্থিত লোকেলের জন্য অ্যাপল ডক্স দিয়ে সাইন ইন দেখুন।

    Web

    provider.setCustomParameters({
      // Localize the Apple authentication screen in French.
      locale: 'fr'
    });

    Web

    provider.setCustomParameters({
      // Localize the Apple authentication screen in French.
      locale: 'fr'
    });
  4. OAuth প্রদানকারী অবজেক্ট ব্যবহার করে Firebase দিয়ে প্রমাণীকরণ করুন। আপনি আপনার ব্যবহারকারীদের একটি পপ-আপ উইন্ডো খোলার মাধ্যমে বা সাইন-ইন পৃষ্ঠায় পুনঃনির্দেশিত করে তাদের Apple অ্যাকাউন্টগুলির সাথে সাইন ইন করতে অনুরোধ করতে পারেন৷ রিডাইরেক্ট পদ্ধতি মোবাইল ডিভাইসে পছন্দ করা হয়।

    • একটি পপ-আপ উইন্ডো দিয়ে সাইন ইন করতে, signInWithPopup() কল করুন :

      Web

      import { getAuth, signInWithPopup, OAuthProvider } from "firebase/auth";
      
      const auth = getAuth();
      signInWithPopup(auth, provider)
        .then((result) => {
          // The signed-in user info.
          const user = result.user;
      
          // Apple credential
          const credential = OAuthProvider.credentialFromResult(result);
          const accessToken = credential.accessToken;
          const idToken = credential.idToken;
      
          // IdP data available using getAdditionalUserInfo(result)
          // ...
        })
        .catch((error) => {
          // Handle Errors here.
          const errorCode = error.code;
          const errorMessage = error.message;
          // The email of the user's account used.
          const email = error.customData.email;
          // The credential that was used.
          const credential = OAuthProvider.credentialFromError(error);
      
          // ...
        });

      Web

      firebase
        .auth()
        .signInWithPopup(provider)
        .then((result) => {
          /** @type {firebase.auth.OAuthCredential} */
          var credential = result.credential;
      
          // The signed-in user info.
          var user = result.user;
      
          // You can also get the Apple OAuth Access and ID Tokens.
          var accessToken = credential.accessToken;
          var idToken = credential.idToken;
      
          // IdP data available using getAdditionalUserInfo(result)
        // ...
        })
        .catch((error) => {
          // Handle Errors here.
          var errorCode = error.code;
          var errorMessage = error.message;
          // The email of the user's account used.
          var email = error.email;
          // The firebase.auth.AuthCredential type that was used.
          var credential = error.credential;
      
          // ...
        });
    • সাইন-ইন পৃষ্ঠায় পুনঃনির্দেশ করে সাইন ইন করতে, signInWithRedirect() কল করুন :

    signInWithRedirect , linkWithRedirect , অথবা reauthenticateWithRedirect ব্যবহার করার সময় সর্বোত্তম অনুশীলনগুলি অনুসরণ করুন৷

    Web

    import { getAuth, signInWithRedirect } from "firebase/auth";
    
    const auth = getAuth();
    signInWithRedirect(auth, provider);

    Web

    firebase.auth().signInWithRedirect(provider);

    ব্যবহারকারী সাইন-ইন সম্পূর্ণ করার পরে এবং পৃষ্ঠায় ফিরে আসার পরে, আপনি getRedirectResult() কল করে সাইন-ইন ফলাফল পেতে পারেন :

    Web

    import { getAuth, getRedirectResult, OAuthProvider } from "firebase/auth";
    
    // Result from Redirect auth flow.
    const auth = getAuth();
    getRedirectResult(auth)
      .then((result) => {
        const credential = OAuthProvider.credentialFromResult(result);
        if (credential) {
          // You can also get the Apple OAuth Access and ID Tokens.
          const accessToken = credential.accessToken;
          const idToken = credential.idToken;
        }
        // The signed-in user info.
        const user = result.user;
      })
      .catch((error) => {
        // Handle Errors here.
        const errorCode = error.code;
        const errorMessage = error.message;
        // The email of the user's account used.
        const email = error.customData.email;
        // The credential that was used.
        const credential = OAuthProvider.credentialFromError(error);
    
        // ...
      });

    Web

    // Result from Redirect auth flow.
    firebase
      .auth()
      .getRedirectResult()
      .then((result) => {
        if (result.credential) {
          /** @type {firebase.auth.OAuthCredential} */
          var credential = result.credential;
    
          // You can get the Apple OAuth Access and ID Tokens.
          var accessToken = credential.accessToken;
          var idToken = credential.idToken;
    
          // IdP data available in result.additionalUserInfo.profile.
          // ...
        }
        // The signed-in user info.
        var user = result.user;
      })
      .catch((error) => {
        // Handle Errors here.
        var errorCode = error.code;
        var errorMessage = error.message;
        // The email of the user's account used.
        var email = error.email;
        // The firebase.auth.AuthCredential type that was used.
        var credential = error.credential;
    
        // ...
      });

    এটিও যেখানে আপনি ত্রুটিগুলি ধরতে এবং পরিচালনা করতে পারেন৷ ত্রুটি কোডের একটি তালিকার জন্য, API রেফারেন্স দেখুন।

    Firebase Auth দ্বারা সমর্থিত অন্যান্য প্রদানকারীদের থেকে ভিন্ন, Apple একটি ফটো URL প্রদান করে না।

    এছাড়াও, ব্যবহারকারী যখন অ্যাপের সাথে তাদের ইমেল শেয়ার না করা বেছে নেয়, তখন অ্যাপল সেই ব্যবহারকারীর জন্য একটি অনন্য ইমেল ঠিকানার ব্যবস্থা করে (ফর্ম xyz@privaterelay.appleid.com ), যা এটি আপনার অ্যাপের সাথে শেয়ার করে। আপনি যদি ব্যক্তিগত ইমেল রিলে পরিষেবা কনফিগার করেন, অ্যাপল ব্যবহারকারীর আসল ইমেল ঠিকানায় বেনামী ঠিকানায় পাঠানো ইমেলগুলি ফরওয়ার্ড করে।

    অ্যাপল শুধুমাত্র ব্যবহারকারীর তথ্য শেয়ার করে যেমন ডিসপ্লে নাম অ্যাপের সাথে প্রথমবার যখন কোনো ব্যবহারকারী সাইন ইন করে। সাধারণত, Firebase ডিসপ্লে নাম সংরক্ষণ করে যখন কোনো ব্যবহারকারী অ্যাপলের সাথে সাইন ইন করে, যা আপনি firebase.auth().currentUser.displayName মাধ্যমে পেতে পারেন। যাইহোক, আপনি যদি আগে Firebase ব্যবহার না করে অ্যাপে কোনো ব্যবহারকারীকে সাইন ইন করার জন্য Apple ব্যবহার করেন, তাহলে Apple ব্যবহারকারীর প্রদর্শনের নাম দিয়ে Firebase প্রদান করবে না।

পুনরায় প্রমাণীকরণ এবং অ্যাকাউন্ট লিঙ্কিং

একই প্যাটার্নটি reauthenticateWithPopup() এবং reauthenticateWithRedirect() এর সাথে ব্যবহার করা যেতে পারে, যা আপনি সাম্প্রতিক সাইন-ইন প্রয়োজন এমন সংবেদনশীল অপারেশনগুলির জন্য একটি নতুন শংসাপত্র পুনরুদ্ধার করতে ব্যবহার করতে পারেন:

Web

import { getAuth, reauthenticateWithPopup, OAuthProvider } from "firebase/auth";

// Result from Redirect auth flow.
const auth = getAuth();
const provider = new OAuthProvider('apple.com');

reauthenticateWithPopup(auth.currentUser, provider)
  .then((result) => {
    // User is re-authenticated with fresh tokens minted and can perform
    // sensitive operations like account deletion, or updating their email
    // address or password.

    // The signed-in user info.
    const user = result.user;

    // You can also get the Apple OAuth Access and ID Tokens.
    const credential = OAuthProvider.credentialFromResult(result);
    const accessToken = credential.accessToken;
    const idToken = credential.idToken;

    // ...
  })
  .catch((error) => {
    // Handle Errors here.
    const errorCode = error.code;
    const errorMessage = error.message;
    // The email of the user's account used.
    const email = error.customData.email;
    // The credential that was used.
    const credential = OAuthProvider.credentialFromError(error);

    // ...
  });

Web

const provider = new firebase.auth.OAuthProvider('apple.com');

firebase
  .auth()
  .currentUser
  .reauthenticateWithPopup(provider)
  .then((result) => {
    // User is re-authenticated with fresh tokens minted and can perform
    // sensitive operations like account deletion, or updating their email
    // address or password.
    /** @type {firebase.auth.OAuthCredential} */
    var credential = result.credential;

    // The signed-in user info.
    var user = result.user;
     // You can also get the Apple OAuth Access and ID Tokens.
    var accessToken = credential.accessToken;
    var idToken = credential.idToken;

    // IdP data available in result.additionalUserInfo.profile.
      // ...
  })
  .catch((error) => {
    // Handle Errors here.
    var errorCode = error.code;
    var errorMessage = error.message;
    // The email of the user's account used.
    var email = error.email;
    // The firebase.auth.AuthCredential type that was used.
    var credential = error.credential;

    // ...
  });

এবং, আপনি বিদ্যমান অ্যাকাউন্টে বিভিন্ন পরিচয় প্রদানকারীকে লিঙ্ক করতে linkWithPopup() এবং linkWithRedirect() ব্যবহার করতে পারেন।

মনে রাখবেন যে অ্যাপল আপনাকে তাদের অ্যাপল অ্যাকাউন্টগুলিকে অন্য ডেটার সাথে লিঙ্ক করার আগে ব্যবহারকারীদের কাছ থেকে স্পষ্ট সম্মতি নিতে হবে।

উদাহরণস্বরূপ, বর্তমান ফায়ারবেস অ্যাকাউন্টের সাথে একটি Facebook অ্যাকাউন্ট লিঙ্ক করতে, ব্যবহারকারীকে Facebook-এ সাইন ইন করার সময় আপনি যে অ্যাক্সেস টোকেন পেয়েছেন তা ব্যবহার করুন:

Web

import { getAuth, linkWithPopup, FacebookAuthProvider } from "firebase/auth";

const auth = getAuth();
const provider = new FacebookAuthProvider();
provider.addScope('user_birthday');

// Assuming the current user is an Apple user linking a Facebook provider.
linkWithPopup(auth.currentUser, provider)
    .then((result) => {
      // Facebook credential is linked to the current Apple user.
      // ...

      // The user can now sign in to the same account
      // with either Apple or Facebook.
    })
    .catch((error) => {
      // Handle error.
    });

Web

const provider = new firebase.auth.FacebookAuthProvider();
provider.addScope('user_birthday');

// Assuming the current user is an Apple user linking a Facebook provider.
firebase.auth().currentUser.linkWithPopup(provider)
    .then((result) => {
      // Facebook credential is linked to the current Apple user.
      // Facebook additional data available in result.additionalUserInfo.profile,

      // Additional Facebook OAuth access token can also be retrieved.
      // result.credential.accessToken

      // The user can now sign in to the same account
      // with either Apple or Facebook.
    })
    .catch((error) => {
      // Handle error.
    });

একটি Chrome এক্সটেনশনে Firebase দিয়ে প্রমাণীকরণ করুন

আপনি যদি একটি Chrome এক্সটেনশন অ্যাপ তৈরি করেন, অফস্ক্রিন ডকুমেন্টস গাইড দেখুন।

মনে রাখবেন যে আপনাকে এখনও Apple-এর সাথে ডিফল্ট firebaseapp.com ডোমেনের মতোই কাস্টম ডোমেন যাচাই করতে হবে:

http://auth.custom.example.com/.well-known/apple-developer-domain-association.txt

টোকেন প্রত্যাহার

অ্যাপলের প্রয়োজন যে অ্যাপগুলি অ্যাকাউন্ট তৈরিকে সমর্থন করে সেগুলিকে অবশ্যই ব্যবহারকারীদের অ্যাপের মধ্যে তাদের অ্যাকাউন্ট মুছে ফেলা শুরু করতে দিতে হবে, যেমন অ্যাপ স্টোর পর্যালোচনা নির্দেশিকাতে বর্ণিত হয়েছে

এই প্রয়োজনীয়তা পূরণ করতে, নিম্নলিখিত পদক্ষেপগুলি বাস্তবায়ন করুন:

  1. নিশ্চিত করুন যে আপনি অ্যাপল প্রদানকারী কনফিগারেশনের সাথে সাইন ইন-এর পরিষেবা আইডি এবং OAuth কোড ফ্লো কনফিগারেশন বিভাগটি পূরণ করেছেন, যেমনটি অ্যাপলের সাথে সাইন ইন কনফিগার করুন বিভাগে বর্ণিত হয়েছে।

  2. যেহেতু Firebase ব্যবহারকারীর টোকেন সংরক্ষণ করে না যখন ব্যবহারকারীরা অ্যাপলের সাথে সাইন ইন করে তৈরি করা হয়, তাই আপনাকে অবশ্যই ব্যবহারকারীকে তাদের টোকেন প্রত্যাহার এবং অ্যাকাউন্ট মুছে ফেলার আগে আবার সাইন ইন করতে বলতে হবে।

    তারপর, OAuthCredential থেকে Apple OAuth অ্যাক্সেস টোকেনটি পান এবং Apple OAuth অ্যাক্সেস টোকেন প্রত্যাহার করতে revokeAccessToken(auth, token) কল করতে এটি ব্যবহার করুন৷

    const provider = new OAuthProvider('apple.com');
    provider.addScope('email');
    provider.addScope('name');
    
    const auth = getAuth();
    signInWithPopup(auth, provider).then(result => {
      // Get the Apple OAuth access token.
      const credential = OAuthProvider.credentialFromResult(result);
      const accessToken = credential.accessToken;
    
      // Revoke the Apple OAuth access token.
      revokeAccessToken(auth, accessToken)
        .then(() => {
          // Token revoked.
    
          // Delete the user account.
          // ...
        })
        .catch(error => {
          // An error happened.
          // ...
        });
    });
    
  3. অবশেষে, ব্যবহারকারীর অ্যাকাউন্ট (এবং সমস্ত সম্পর্কিত ডেটা) মুছুন

উন্নত: Node.js-এ Firebase দিয়ে প্রমাণীকরণ করুন

একটি Node.js অ্যাপ্লিকেশনে ফায়ারবেসের সাথে প্রমাণীকরণ করতে:

  1. ব্যবহারকারীকে তাদের অ্যাপল অ্যাকাউন্ট দিয়ে সাইন ইন করুন এবং ব্যবহারকারীর অ্যাপল আইডি টোকেন পান। আপনি এটি বিভিন্ন উপায়ে সম্পন্ন করতে পারেন। উদাহরণস্বরূপ, যদি আপনার Node.js অ্যাপের একটি ব্রাউজার ফ্রন্ট এন্ড থাকে:

    1. আপনার ব্যাকএন্ডে, একটি এলোমেলো স্ট্রিং তৈরি করুন (একটি "নন্স") এবং এর SHA256 হ্যাশ গণনা করুন। ননস হল একটি এককালীন ব্যবহারের মান যা আপনি আপনার ব্যাকএন্ড এবং Apple এর প্রমাণীকরণ সার্ভারগুলির মধ্যে একটি একক রাউন্ড ট্রিপ যাচাই করতে ব্যবহার করেন৷

      Web

      const crypto = require("crypto");
      const string_decoder = require("string_decoder");
      
      // Generate a new random string for each sign-in
      const generateNonce = (length) => {
        const decoder = new string_decoder.StringDecoder("ascii");
        const buf = Buffer.alloc(length);
        let nonce = "";
        while (nonce.length < length) {
          crypto.randomFillSync(buf);
          nonce = decoder.write(buf);
        }
        return nonce.slice(0, length);
      };
      
      const unhashedNonce = generateNonce(10);
      
      // SHA256-hashed nonce in hex
      const hashedNonceHex = crypto.createHash('sha256')
        .update(unhashedNonce).digest().toString('hex');

      Web

      const crypto = require("crypto");
      const string_decoder = require("string_decoder");
      
      // Generate a new random string for each sign-in
      const generateNonce = function(length) {
        const decoder = new string_decoder.StringDecoder("ascii");
        const buf = Buffer.alloc(length);
        var nonce = "";
        while (nonce.length < length) {
          crypto.randomFillSync(buf);
          nonce = decoder.write(buf);
        }
        return nonce.slice(0, length);
      };
      
      const unhashedNonce = generateNonce(10);
      
      // SHA256-hashed nonce in hex
      const hashedNonceHex = crypto.createHash('sha256')
        .update(unhashedNonce).digest().toString('hex');
    2. আপনার সাইন-ইন পৃষ্ঠায়, অ্যাপল কনফিগারেশনের সাথে আপনার সাইন ইনে হ্যাশড ননস উল্লেখ করুন:

      <script src="https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js"></script>
      <div id="appleid-signin" data-color="black" data-border="true" data-type="sign in"></div>
      <script>
          AppleID.auth.init({
              clientId: YOUR_APPLE_CLIENT_ID,
              scope: 'name email',
              redirectURI: URL_TO_YOUR_REDIRECT_HANDLER,  // See the next step.
              state: '[STATE]',  // Optional value that Apple will send back to you
                                 // so you can return users to the same context after
                                 // they sign in.
              nonce: HASHED_NONCE  // The hashed nonce you generated in the previous step.
          });
      </script>
      
    3. পোস্ট করা প্রমাণীকরণ প্রতিক্রিয়া সার্ভার-সাইড থেকে অ্যাপল আইডি টোকেন পান:

      app.post('/redirect', (req, res) => {
        const savedState = req.cookies.__session;
        const code = req.body.code;
        const state = req.body.state;
        const appleIdToken = req.body.id_token;
        if (savedState !== state || !code) {
          res.status(403).send('403: Permission denied');
        } else {
          // Sign in with Firebase using appleIdToken. (See next step).
        }
      });
      

    এছাড়াও অ্যাপলের সাথে সাইন ইন করার জন্য আপনার ওয়েবপৃষ্ঠা কনফিগার করা দেখুন।

  2. আপনি ব্যবহারকারীর অ্যাপল আইডি টোকেন পাওয়ার পরে, একটি শংসাপত্র বস্তু তৈরি করতে এটি ব্যবহার করুন এবং তারপরে শংসাপত্রের সাথে ব্যবহারকারীকে সাইন ইন করুন:

    Web

    import { getAuth, signInWithCredential, OAuthProvider } from "firebase/auth";
    
    const auth = getAuth();
    
    // Build Firebase credential with the Apple ID token.
    const provider = new OAuthProvider('apple.com');
    const authCredential = provider.credential({
      idToken: appleIdToken,
      rawNonce: unhashedNonce,
    });
    
    // Sign in with credential form the Apple user.
    signInWithCredential(auth, authCredential)
      .then((result) => {
        // User signed in.
      })
      .catch((error) => {
        // An error occurred. If error.code == 'auth/missing-or-invalid-nonce',
        // make sure you're sending the SHA256-hashed nonce as a hex string
        // with your request to Apple.
        console.log(error);
      });

    Web

    // Build Firebase credential with the Apple ID token.
    const provider = new firebase.auth.OAuthProvider('apple.com');
    const authCredential = provider.credential({
      idToken: appleIdToken,
      rawNonce: unhashedNonce,
    });
    
    // Sign in with credential form the Apple user.
    firebase.auth().signInWithCredential(authCredential)
      .then((result) => {
        // User signed in.
      })
      .catch((error) => {
        // An error occurred. If error.code == 'auth/missing-or-invalid-nonce',
        // make sure you're sending the SHA256-hashed nonce as a hex string
        // with your request to Apple.
        console.log(error);
      });

পরবর্তী পদক্ষেপ

একজন ব্যবহারকারী প্রথমবার সাইন ইন করার পরে, একটি নতুন ব্যবহারকারীর অ্যাকাউন্ট তৈরি করা হয় এবং শংসাপত্রগুলির সাথে লিঙ্ক করা হয়—অর্থাৎ, ব্যবহারকারীর নাম এবং পাসওয়ার্ড, ফোন নম্বর, বা প্রমাণ প্রদানকারীর তথ্য — ব্যবহারকারী সাইন ইন করেছেন। এই নতুন অ্যাকাউন্টটি আপনার ফায়ারবেস প্রকল্পের অংশ হিসাবে সংরক্ষণ করা হয়েছে এবং ব্যবহারকারী কীভাবে সাইন ইন করুন না কেন, আপনার প্রকল্পের প্রতিটি অ্যাপ জুড়ে একজন ব্যবহারকারীকে শনাক্ত করতে ব্যবহার করা যেতে পারে।

  • আপনার অ্যাপে, আপনার ব্যবহারকারীর প্রমাণীকরণের স্থিতি জানার প্রস্তাবিত উপায় হল Auth অবজেক্টে একজন পর্যবেক্ষক সেট করা। তারপর আপনি User অবজেক্ট থেকে ব্যবহারকারীর মৌলিক প্রোফাইল তথ্য পেতে পারেন। ব্যবহারকারীদের পরিচালনা দেখুন।

  • In your Firebase Realtime Database and Cloud Storage Security Rules , you can get the signed-in user's unique user ID from the auth variable, and use it to control what data a user can access.

আপনি একটি বিদ্যমান ব্যবহারকারীর অ্যাকাউন্টে প্রমাণীকরণ প্রদানকারীর শংসাপত্র লিঙ্ক করে একাধিক প্রমাণীকরণ প্রদানকারী ব্যবহার করে ব্যবহারকারীদের আপনার অ্যাপে সাইন ইন করার অনুমতি দিতে পারেন।

একজন ব্যবহারকারীকে সাইন আউট করতে, signOut কল করুন:

Web

import { getAuth, signOut } from "firebase/auth";

const auth = getAuth();
signOut(auth).then(() => {
  // Sign-out successful.
}).catch((error) => {
  // An error happened.
});

Web

firebase.auth().signOut().then(() => {
  // Sign-out successful.
}).catch((error) => {
  // An error happened.
});
,

এন্ড-টু-এন্ড OAuth 2.0 সাইন-ইন ফ্লো চালানোর জন্য আপনি Firebase SDK ব্যবহার করে আপনার ব্যবহারকারীদের তাদের Apple ID ব্যবহার করে Firebase-এর সাথে প্রমাণীকরণ করতে দিতে পারেন।

আপনি শুরু করার আগে

Apple ব্যবহার করে ব্যবহারকারীদের সাইন ইন করতে, প্রথমে Apple এর বিকাশকারী সাইটে Apple এর সাথে সাইন ইন কনফিগার করুন, তারপর আপনার Firebase প্রকল্পের জন্য একটি সাইন-ইন প্রদানকারী হিসাবে Apple সক্ষম করুন৷

অ্যাপল ডেভেলপার প্রোগ্রামে যোগ দিন

Apple এর সাথে সাইন ইন শুধুমাত্র Apple বিকাশকারী প্রোগ্রামের সদস্যদের দ্বারা কনফিগার করা যেতে পারে৷

অ্যাপল দিয়ে সাইন ইন কনফিগার করুন

অ্যাপল বিকাশকারী সাইটে, নিম্নলিখিতগুলি করুন:

  1. ওয়েবের জন্য Apple এর সাথে কনফিগার সাইন ইনের প্রথম বিভাগে বর্ণিত হিসাবে আপনার অ্যাপের সাথে আপনার ওয়েবসাইট যুক্ত করুন৷ অনুরোধ করা হলে, একটি রিটার্ন ইউআরএল হিসাবে নিম্নলিখিত URL নিবন্ধন করুন:

    https://YOUR_FIREBASE_PROJECT_ID.firebaseapp.com/__/auth/handler

    আপনি Firebase কনসোল সেটিংস পৃষ্ঠায় আপনার Firebase প্রকল্প আইডি পেতে পারেন।

    আপনার হয়ে গেলে, আপনার নতুন পরিষেবা আইডি নোট করুন, যা আপনাকে পরবর্তী বিভাগে প্রয়োজন হবে৷

  2. অ্যাপল ব্যক্তিগত কী দিয়ে একটি সাইন ইন তৈরি করুন । পরবর্তী বিভাগে আপনার নতুন ব্যক্তিগত কী এবং কী আইডির প্রয়োজন হবে৷
  3. If you use any of Firebase Authentication 's features that send emails to users, including email link sign-in, email address verification, account change revocation, and others, configure the Apple private email relay service and register noreply@ YOUR_FIREBASE_PROJECT_ID .firebaseapp.com (or your customized email template domain) so Apple can relay emails sent by Firebase Authentication বেনামী অ্যাপল ইমেল ঠিকানায়.

একটি সাইন-ইন প্রদানকারী হিসাবে Apple সক্ষম করুন৷

  1. আপনার প্রকল্পে Firebase যোগ করুন
  2. Firebase কনসোলে , Auth বিভাগটি খুলুন। সাইন ইন পদ্ধতি ট্যাবে, অ্যাপল প্রদানকারী সক্ষম করুন। পূর্ববর্তী বিভাগে আপনি যে পরিষেবা আইডি তৈরি করেছেন তা উল্লেখ করুন। এছাড়াও, OAuth কোড ফ্লো কনফিগারেশন বিভাগে , আপনার Apple টিম আইডি এবং পূর্ববর্তী বিভাগে আপনার তৈরি করা ব্যক্তিগত কী এবং কী আইডি উল্লেখ করুন।

অ্যাপল বেনামী ডেটা প্রয়োজনীয়তা মেনে চলুন

অ্যাপলের সাথে সাইন ইন ব্যবহারকারীদের সাইন ইন করার সময় তাদের ইমেল ঠিকানা সহ তাদের ডেটা বেনামী করার বিকল্প দেয়৷ যে ব্যবহারকারীরা এই বিকল্পটি বেছে নেন তাদের কাছে privaterelay.appleid.com ডোমেনের ইমেল ঠিকানা রয়েছে৷ আপনি যখন আপনার অ্যাপে Apple এর সাথে সাইন ইন ব্যবহার করেন, তখন আপনাকে অবশ্যই এই বেনামী Apple ID সংক্রান্ত যেকোন প্রযোজ্য বিকাশকারী নীতি বা Apple থেকে শর্তাবলী মেনে চলতে হবে।

আপনি একটি বেনামী অ্যাপল আইডির সাথে সরাসরি সনাক্তকারী ব্যক্তিগত তথ্য সংযুক্ত করার আগে যেকোন প্রয়োজনীয় ব্যবহারকারীর সম্মতি প্রাপ্ত করা এর মধ্যে রয়েছে। ফায়ারবেস প্রমাণীকরণ ব্যবহার করার সময়, এতে নিম্নলিখিত ক্রিয়াগুলি অন্তর্ভুক্ত থাকতে পারে:

  • একটি বেনামী অ্যাপল আইডি বা বিপরীতে একটি ইমেল ঠিকানা লিঙ্ক করুন.
  • একটি বেনামী অ্যাপল আইডিতে একটি ফোন নম্বর লিঙ্ক করুন বা এর বিপরীতে
  • একটি বেনামী সামাজিক শংসাপত্র (ফেসবুক, গুগল, ইত্যাদি) একটি বেনামী অ্যাপল আইডিতে বা এর বিপরীতে লিঙ্ক করুন৷

উপরের তালিকাটি সম্পূর্ণ নয়। আপনার অ্যাপ অ্যাপলের প্রয়োজনীয়তা পূরণ করছে তা নিশ্চিত করতে আপনার ডেভেলপার অ্যাকাউন্টের সদস্যপদ বিভাগে অ্যাপল ডেভেলপার প্রোগ্রাম লাইসেন্স চুক্তি পড়ুন।

Firebase SDK দিয়ে সাইন-ইন ফ্লো পরিচালনা করুন

আপনি যদি একটি ওয়েব অ্যাপ তৈরি করেন, তাহলে আপনার ব্যবহারকারীদের Firebase-এর মাধ্যমে তাদের Apple অ্যাকাউন্ট ব্যবহার করে প্রমাণীকরণ করার সবচেয়ে সহজ উপায় হল Firebase JavaScript SDK-এর মাধ্যমে সম্পূর্ণ সাইন-ইন প্রবাহ পরিচালনা করা।

Firebase JavaScript SDK দিয়ে সাইন-ইন প্রবাহ পরিচালনা করতে, এই ধাপগুলি অনুসরণ করুন:

  1. সংশ্লিষ্ট প্রদানকারী আইডি apple.com ব্যবহার করে একটি OAuthProvider- এর একটি উদাহরণ তৈরি করুন।

    Web

    import { OAuthProvider } from "firebase/auth";
    
    const provider = new OAuthProvider('apple.com');

    Web

    var provider = new firebase.auth.OAuthProvider('apple.com');
  2. ঐচ্ছিক: ডিফল্টের বাইরে অতিরিক্ত OAuth 2.0 স্কোপ নির্দিষ্ট করুন যা আপনি প্রমাণীকরণ প্রদানকারীর কাছ থেকে অনুরোধ করতে চান।

    Web

    provider.addScope('email');
    provider.addScope('name');

    Web

    provider.addScope('email');
    provider.addScope('name');

    ডিফল্টরূপে, যখন প্রতি ইমেল ঠিকানায় একটি অ্যাকাউন্ট সক্রিয় থাকে, তখন Firebase ইমেল এবং নামের সুযোগের অনুরোধ করে। আপনি যদি এই সেটিংটি প্রতি ইমেল ঠিকানায় একাধিক অ্যাকাউন্টে পরিবর্তন করেন, তাহলে Firebase অ্যাপল থেকে কোনো সুযোগের অনুরোধ করে না যদি না আপনি সেগুলি নির্দিষ্ট করেন।

  3. ঐচ্ছিক: আপনি যদি ইংরেজি ছাড়া অন্য কোনো ভাষায় Apple-এর সাইন-ইন স্ক্রীন প্রদর্শন করতে চান, তাহলে locale প্যারামিটার সেট করুন। সমর্থিত লোকেলের জন্য অ্যাপল ডক্স দিয়ে সাইন ইন দেখুন।

    Web

    provider.setCustomParameters({
      // Localize the Apple authentication screen in French.
      locale: 'fr'
    });

    Web

    provider.setCustomParameters({
      // Localize the Apple authentication screen in French.
      locale: 'fr'
    });
  4. OAuth প্রদানকারী অবজেক্ট ব্যবহার করে Firebase দিয়ে প্রমাণীকরণ করুন। আপনি আপনার ব্যবহারকারীদের একটি পপ-আপ উইন্ডো খোলার মাধ্যমে বা সাইন-ইন পৃষ্ঠায় পুনঃনির্দেশিত করে তাদের Apple অ্যাকাউন্টগুলির সাথে সাইন ইন করতে অনুরোধ করতে পারেন৷ রিডাইরেক্ট পদ্ধতি মোবাইল ডিভাইসে পছন্দ করা হয়।

    • একটি পপ-আপ উইন্ডো দিয়ে সাইন ইন করতে, signInWithPopup() কল করুন :

      Web

      import { getAuth, signInWithPopup, OAuthProvider } from "firebase/auth";
      
      const auth = getAuth();
      signInWithPopup(auth, provider)
        .then((result) => {
          // The signed-in user info.
          const user = result.user;
      
          // Apple credential
          const credential = OAuthProvider.credentialFromResult(result);
          const accessToken = credential.accessToken;
          const idToken = credential.idToken;
      
          // IdP data available using getAdditionalUserInfo(result)
          // ...
        })
        .catch((error) => {
          // Handle Errors here.
          const errorCode = error.code;
          const errorMessage = error.message;
          // The email of the user's account used.
          const email = error.customData.email;
          // The credential that was used.
          const credential = OAuthProvider.credentialFromError(error);
      
          // ...
        });

      Web

      firebase
        .auth()
        .signInWithPopup(provider)
        .then((result) => {
          /** @type {firebase.auth.OAuthCredential} */
          var credential = result.credential;
      
          // The signed-in user info.
          var user = result.user;
      
          // You can also get the Apple OAuth Access and ID Tokens.
          var accessToken = credential.accessToken;
          var idToken = credential.idToken;
      
          // IdP data available using getAdditionalUserInfo(result)
        // ...
        })
        .catch((error) => {
          // Handle Errors here.
          var errorCode = error.code;
          var errorMessage = error.message;
          // The email of the user's account used.
          var email = error.email;
          // The firebase.auth.AuthCredential type that was used.
          var credential = error.credential;
      
          // ...
        });
    • সাইন-ইন পৃষ্ঠায় পুনঃনির্দেশ করে সাইন ইন করতে, signInWithRedirect() কল করুন :

    signInWithRedirect , linkWithRedirect , অথবা reauthenticateWithRedirect ব্যবহার করার সময় সর্বোত্তম অনুশীলনগুলি অনুসরণ করুন৷

    Web

    import { getAuth, signInWithRedirect } from "firebase/auth";
    
    const auth = getAuth();
    signInWithRedirect(auth, provider);

    Web

    firebase.auth().signInWithRedirect(provider);

    ব্যবহারকারী সাইন-ইন সম্পূর্ণ করার পরে এবং পৃষ্ঠায় ফিরে আসার পরে, আপনি getRedirectResult() কল করে সাইন-ইন ফলাফল পেতে পারেন :

    Web

    import { getAuth, getRedirectResult, OAuthProvider } from "firebase/auth";
    
    // Result from Redirect auth flow.
    const auth = getAuth();
    getRedirectResult(auth)
      .then((result) => {
        const credential = OAuthProvider.credentialFromResult(result);
        if (credential) {
          // You can also get the Apple OAuth Access and ID Tokens.
          const accessToken = credential.accessToken;
          const idToken = credential.idToken;
        }
        // The signed-in user info.
        const user = result.user;
      })
      .catch((error) => {
        // Handle Errors here.
        const errorCode = error.code;
        const errorMessage = error.message;
        // The email of the user's account used.
        const email = error.customData.email;
        // The credential that was used.
        const credential = OAuthProvider.credentialFromError(error);
    
        // ...
      });

    Web

    // Result from Redirect auth flow.
    firebase
      .auth()
      .getRedirectResult()
      .then((result) => {
        if (result.credential) {
          /** @type {firebase.auth.OAuthCredential} */
          var credential = result.credential;
    
          // You can get the Apple OAuth Access and ID Tokens.
          var accessToken = credential.accessToken;
          var idToken = credential.idToken;
    
          // IdP data available in result.additionalUserInfo.profile.
          // ...
        }
        // The signed-in user info.
        var user = result.user;
      })
      .catch((error) => {
        // Handle Errors here.
        var errorCode = error.code;
        var errorMessage = error.message;
        // The email of the user's account used.
        var email = error.email;
        // The firebase.auth.AuthCredential type that was used.
        var credential = error.credential;
    
        // ...
      });

    এটিও যেখানে আপনি ত্রুটিগুলি ধরতে এবং পরিচালনা করতে পারেন৷ ত্রুটি কোডের একটি তালিকার জন্য, API রেফারেন্স দেখুন।

    Firebase Auth দ্বারা সমর্থিত অন্যান্য প্রদানকারীদের থেকে ভিন্ন, Apple একটি ফটো URL প্রদান করে না।

    এছাড়াও, ব্যবহারকারী যখন অ্যাপের সাথে তাদের ইমেল শেয়ার না করা বেছে নেয়, তখন অ্যাপল সেই ব্যবহারকারীর জন্য একটি অনন্য ইমেল ঠিকানার ব্যবস্থা করে (ফর্ম xyz@privaterelay.appleid.com ), যা এটি আপনার অ্যাপের সাথে শেয়ার করে। আপনি যদি ব্যক্তিগত ইমেল রিলে পরিষেবা কনফিগার করেন, অ্যাপল ব্যবহারকারীর আসল ইমেল ঠিকানায় বেনামী ঠিকানায় পাঠানো ইমেলগুলি ফরওয়ার্ড করে।

    অ্যাপল শুধুমাত্র ব্যবহারকারীর তথ্য শেয়ার করে যেমন ডিসপ্লে নাম অ্যাপের সাথে প্রথমবার যখন কোনো ব্যবহারকারী সাইন ইন করে। সাধারণত, Firebase ডিসপ্লে নাম সংরক্ষণ করে যখন কোনো ব্যবহারকারী অ্যাপলের সাথে সাইন ইন করে, যা আপনি firebase.auth().currentUser.displayName মাধ্যমে পেতে পারেন। যাইহোক, আপনি যদি আগে Firebase ব্যবহার না করে অ্যাপে কোনো ব্যবহারকারীকে সাইন ইন করার জন্য Apple ব্যবহার করেন, তাহলে Apple ব্যবহারকারীর প্রদর্শনের নাম দিয়ে Firebase প্রদান করবে না।

পুনরায় প্রমাণীকরণ এবং অ্যাকাউন্ট লিঙ্কিং

একই প্যাটার্নটি reauthenticateWithPopup() এবং reauthenticateWithRedirect() এর সাথে ব্যবহার করা যেতে পারে, যা আপনি সাম্প্রতিক সাইন-ইন প্রয়োজন এমন সংবেদনশীল অপারেশনগুলির জন্য একটি নতুন শংসাপত্র পুনরুদ্ধার করতে ব্যবহার করতে পারেন:

Web

import { getAuth, reauthenticateWithPopup, OAuthProvider } from "firebase/auth";

// Result from Redirect auth flow.
const auth = getAuth();
const provider = new OAuthProvider('apple.com');

reauthenticateWithPopup(auth.currentUser, provider)
  .then((result) => {
    // User is re-authenticated with fresh tokens minted and can perform
    // sensitive operations like account deletion, or updating their email
    // address or password.

    // The signed-in user info.
    const user = result.user;

    // You can also get the Apple OAuth Access and ID Tokens.
    const credential = OAuthProvider.credentialFromResult(result);
    const accessToken = credential.accessToken;
    const idToken = credential.idToken;

    // ...
  })
  .catch((error) => {
    // Handle Errors here.
    const errorCode = error.code;
    const errorMessage = error.message;
    // The email of the user's account used.
    const email = error.customData.email;
    // The credential that was used.
    const credential = OAuthProvider.credentialFromError(error);

    // ...
  });

Web

const provider = new firebase.auth.OAuthProvider('apple.com');

firebase
  .auth()
  .currentUser
  .reauthenticateWithPopup(provider)
  .then((result) => {
    // User is re-authenticated with fresh tokens minted and can perform
    // sensitive operations like account deletion, or updating their email
    // address or password.
    /** @type {firebase.auth.OAuthCredential} */
    var credential = result.credential;

    // The signed-in user info.
    var user = result.user;
     // You can also get the Apple OAuth Access and ID Tokens.
    var accessToken = credential.accessToken;
    var idToken = credential.idToken;

    // IdP data available in result.additionalUserInfo.profile.
      // ...
  })
  .catch((error) => {
    // Handle Errors here.
    var errorCode = error.code;
    var errorMessage = error.message;
    // The email of the user's account used.
    var email = error.email;
    // The firebase.auth.AuthCredential type that was used.
    var credential = error.credential;

    // ...
  });

এবং, আপনি বিদ্যমান অ্যাকাউন্টে বিভিন্ন পরিচয় প্রদানকারীকে লিঙ্ক করতে linkWithPopup() এবং linkWithRedirect() ব্যবহার করতে পারেন।

মনে রাখবেন যে অ্যাপল আপনাকে তাদের অ্যাপল অ্যাকাউন্টগুলিকে অন্য ডেটার সাথে লিঙ্ক করার আগে ব্যবহারকারীদের কাছ থেকে স্পষ্ট সম্মতি নিতে হবে।

উদাহরণস্বরূপ, বর্তমান ফায়ারবেস অ্যাকাউন্টের সাথে একটি Facebook অ্যাকাউন্ট লিঙ্ক করতে, ব্যবহারকারীকে Facebook-এ সাইন ইন করার সময় আপনি যে অ্যাক্সেস টোকেন পেয়েছেন তা ব্যবহার করুন:

Web

import { getAuth, linkWithPopup, FacebookAuthProvider } from "firebase/auth";

const auth = getAuth();
const provider = new FacebookAuthProvider();
provider.addScope('user_birthday');

// Assuming the current user is an Apple user linking a Facebook provider.
linkWithPopup(auth.currentUser, provider)
    .then((result) => {
      // Facebook credential is linked to the current Apple user.
      // ...

      // The user can now sign in to the same account
      // with either Apple or Facebook.
    })
    .catch((error) => {
      // Handle error.
    });

Web

const provider = new firebase.auth.FacebookAuthProvider();
provider.addScope('user_birthday');

// Assuming the current user is an Apple user linking a Facebook provider.
firebase.auth().currentUser.linkWithPopup(provider)
    .then((result) => {
      // Facebook credential is linked to the current Apple user.
      // Facebook additional data available in result.additionalUserInfo.profile,

      // Additional Facebook OAuth access token can also be retrieved.
      // result.credential.accessToken

      // The user can now sign in to the same account
      // with either Apple or Facebook.
    })
    .catch((error) => {
      // Handle error.
    });

একটি Chrome এক্সটেনশনে Firebase দিয়ে প্রমাণীকরণ করুন

আপনি যদি একটি Chrome এক্সটেনশন অ্যাপ তৈরি করেন, অফস্ক্রিন ডকুমেন্টস গাইড দেখুন।

মনে রাখবেন যে আপনাকে এখনও Apple-এর সাথে ডিফল্ট firebaseapp.com ডোমেনের মতোই কাস্টম ডোমেন যাচাই করতে হবে:

http://auth.custom.example.com/.well-known/apple-developer-domain-association.txt

টোকেন প্রত্যাহার

অ্যাপলের প্রয়োজন যে অ্যাপগুলি অ্যাকাউন্ট তৈরিকে সমর্থন করে সেগুলিকে অবশ্যই ব্যবহারকারীদের অ্যাপের মধ্যে তাদের অ্যাকাউন্ট মুছে ফেলা শুরু করতে দিতে হবে, যেমন অ্যাপ স্টোর পর্যালোচনা নির্দেশিকাতে বর্ণিত হয়েছে

এই প্রয়োজনীয়তা পূরণ করতে, নিম্নলিখিত পদক্ষেপগুলি বাস্তবায়ন করুন:

  1. নিশ্চিত করুন যে আপনি অ্যাপল প্রদানকারী কনফিগারেশনের সাথে সাইন ইন-এর পরিষেবা আইডি এবং OAuth কোড ফ্লো কনফিগারেশন বিভাগটি পূরণ করেছেন, যেমনটি অ্যাপলের সাথে সাইন ইন কনফিগার করুন বিভাগে বর্ণিত হয়েছে।

  2. যেহেতু Firebase ব্যবহারকারীর টোকেন সংরক্ষণ করে না যখন ব্যবহারকারীরা অ্যাপলের সাথে সাইন ইন করে তৈরি করা হয়, তাই আপনাকে অবশ্যই ব্যবহারকারীকে তাদের টোকেন প্রত্যাহার এবং অ্যাকাউন্ট মুছে ফেলার আগে আবার সাইন ইন করতে বলতে হবে।

    তারপর, OAuthCredential থেকে Apple OAuth অ্যাক্সেস টোকেনটি পান এবং Apple OAuth অ্যাক্সেস টোকেন প্রত্যাহার করতে revokeAccessToken(auth, token) কল করতে এটি ব্যবহার করুন৷

    const provider = new OAuthProvider('apple.com');
    provider.addScope('email');
    provider.addScope('name');
    
    const auth = getAuth();
    signInWithPopup(auth, provider).then(result => {
      // Get the Apple OAuth access token.
      const credential = OAuthProvider.credentialFromResult(result);
      const accessToken = credential.accessToken;
    
      // Revoke the Apple OAuth access token.
      revokeAccessToken(auth, accessToken)
        .then(() => {
          // Token revoked.
    
          // Delete the user account.
          // ...
        })
        .catch(error => {
          // An error happened.
          // ...
        });
    });
    
  3. অবশেষে, ব্যবহারকারীর অ্যাকাউন্ট (এবং সমস্ত সম্পর্কিত ডেটা) মুছুন

উন্নত: Node.js-এ Firebase দিয়ে প্রমাণীকরণ করুন

একটি Node.js অ্যাপ্লিকেশনে ফায়ারবেসের সাথে প্রমাণীকরণ করতে:

  1. ব্যবহারকারীকে তাদের অ্যাপল অ্যাকাউন্ট দিয়ে সাইন ইন করুন এবং ব্যবহারকারীর অ্যাপল আইডি টোকেন পান। আপনি এটি বিভিন্ন উপায়ে সম্পন্ন করতে পারেন। উদাহরণস্বরূপ, যদি আপনার Node.js অ্যাপের একটি ব্রাউজার ফ্রন্ট এন্ড থাকে:

    1. আপনার ব্যাকএন্ডে, একটি এলোমেলো স্ট্রিং তৈরি করুন (একটি "নন্স") এবং এর SHA256 হ্যাশ গণনা করুন। ননস হল একটি এককালীন ব্যবহারের মান যা আপনি আপনার ব্যাকএন্ড এবং Apple এর প্রমাণীকরণ সার্ভারগুলির মধ্যে একটি একক রাউন্ড ট্রিপ যাচাই করতে ব্যবহার করেন৷

      Web

      const crypto = require("crypto");
      const string_decoder = require("string_decoder");
      
      // Generate a new random string for each sign-in
      const generateNonce = (length) => {
        const decoder = new string_decoder.StringDecoder("ascii");
        const buf = Buffer.alloc(length);
        let nonce = "";
        while (nonce.length < length) {
          crypto.randomFillSync(buf);
          nonce = decoder.write(buf);
        }
        return nonce.slice(0, length);
      };
      
      const unhashedNonce = generateNonce(10);
      
      // SHA256-hashed nonce in hex
      const hashedNonceHex = crypto.createHash('sha256')
        .update(unhashedNonce).digest().toString('hex');

      Web

      const crypto = require("crypto");
      const string_decoder = require("string_decoder");
      
      // Generate a new random string for each sign-in
      const generateNonce = function(length) {
        const decoder = new string_decoder.StringDecoder("ascii");
        const buf = Buffer.alloc(length);
        var nonce = "";
        while (nonce.length < length) {
          crypto.randomFillSync(buf);
          nonce = decoder.write(buf);
        }
        return nonce.slice(0, length);
      };
      
      const unhashedNonce = generateNonce(10);
      
      // SHA256-hashed nonce in hex
      const hashedNonceHex = crypto.createHash('sha256')
        .update(unhashedNonce).digest().toString('hex');
    2. আপনার সাইন-ইন পৃষ্ঠায়, অ্যাপল কনফিগারেশনের সাথে আপনার সাইন ইনে হ্যাশড ননস উল্লেখ করুন:

      <script src="https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js"></script>
      <div id="appleid-signin" data-color="black" data-border="true" data-type="sign in"></div>
      <script>
          AppleID.auth.init({
              clientId: YOUR_APPLE_CLIENT_ID,
              scope: 'name email',
              redirectURI: URL_TO_YOUR_REDIRECT_HANDLER,  // See the next step.
              state: '[STATE]',  // Optional value that Apple will send back to you
                                 // so you can return users to the same context after
                                 // they sign in.
              nonce: HASHED_NONCE  // The hashed nonce you generated in the previous step.
          });
      </script>
      
    3. পোস্ট করা প্রমাণীকরণ প্রতিক্রিয়া সার্ভার-সাইড থেকে অ্যাপল আইডি টোকেন পান:

      app.post('/redirect', (req, res) => {
        const savedState = req.cookies.__session;
        const code = req.body.code;
        const state = req.body.state;
        const appleIdToken = req.body.id_token;
        if (savedState !== state || !code) {
          res.status(403).send('403: Permission denied');
        } else {
          // Sign in with Firebase using appleIdToken. (See next step).
        }
      });
      

    এছাড়াও অ্যাপলের সাথে সাইন ইন করার জন্য আপনার ওয়েবপৃষ্ঠা কনফিগার করা দেখুন।

  2. আপনি ব্যবহারকারীর অ্যাপল আইডি টোকেন পাওয়ার পরে, একটি শংসাপত্র বস্তু তৈরি করতে এটি ব্যবহার করুন এবং তারপরে শংসাপত্রের সাথে ব্যবহারকারীকে সাইন ইন করুন:

    Web

    import { getAuth, signInWithCredential, OAuthProvider } from "firebase/auth";
    
    const auth = getAuth();
    
    // Build Firebase credential with the Apple ID token.
    const provider = new OAuthProvider('apple.com');
    const authCredential = provider.credential({
      idToken: appleIdToken,
      rawNonce: unhashedNonce,
    });
    
    // Sign in with credential form the Apple user.
    signInWithCredential(auth, authCredential)
      .then((result) => {
        // User signed in.
      })
      .catch((error) => {
        // An error occurred. If error.code == 'auth/missing-or-invalid-nonce',
        // make sure you're sending the SHA256-hashed nonce as a hex string
        // with your request to Apple.
        console.log(error);
      });

    Web

    // Build Firebase credential with the Apple ID token.
    const provider = new firebase.auth.OAuthProvider('apple.com');
    const authCredential = provider.credential({
      idToken: appleIdToken,
      rawNonce: unhashedNonce,
    });
    
    // Sign in with credential form the Apple user.
    firebase.auth().signInWithCredential(authCredential)
      .then((result) => {
        // User signed in.
      })
      .catch((error) => {
        // An error occurred. If error.code == 'auth/missing-or-invalid-nonce',
        // make sure you're sending the SHA256-hashed nonce as a hex string
        // with your request to Apple.
        console.log(error);
      });

পরবর্তী পদক্ষেপ

একজন ব্যবহারকারী প্রথমবার সাইন ইন করার পরে, একটি নতুন ব্যবহারকারীর অ্যাকাউন্ট তৈরি করা হয় এবং শংসাপত্রগুলির সাথে লিঙ্ক করা হয়—অর্থাৎ, ব্যবহারকারীর নাম এবং পাসওয়ার্ড, ফোন নম্বর, বা প্রমাণ প্রদানকারীর তথ্য — ব্যবহারকারী সাইন ইন করেছেন। এই নতুন অ্যাকাউন্টটি আপনার ফায়ারবেস প্রকল্পের অংশ হিসাবে সংরক্ষণ করা হয়েছে এবং ব্যবহারকারী কীভাবে সাইন ইন করুন না কেন, আপনার প্রকল্পের প্রতিটি অ্যাপ জুড়ে একজন ব্যবহারকারীকে শনাক্ত করতে ব্যবহার করা যেতে পারে।

  • আপনার অ্যাপে, আপনার ব্যবহারকারীর প্রমাণীকরণের স্থিতি জানার প্রস্তাবিত উপায় হল Auth অবজেক্টে একজন পর্যবেক্ষক সেট করা। তারপর আপনি User অবজেক্ট থেকে ব্যবহারকারীর মৌলিক প্রোফাইল তথ্য পেতে পারেন। ব্যবহারকারীদের পরিচালনা দেখুন।

  • আপনার Firebase Realtime Database এবং Cloud Storage সুরক্ষা নিয়মে , আপনি auth ভেরিয়েবল থেকে সাইন-ইন করা ব্যবহারকারীর অনন্য ব্যবহারকারী আইডি পেতে পারেন এবং ব্যবহারকারী কোন ডেটা অ্যাক্সেস করতে পারে তা নিয়ন্ত্রণ করতে এটি ব্যবহার করতে পারেন।

আপনি একটি বিদ্যমান ব্যবহারকারীর অ্যাকাউন্টে প্রমাণীকরণ প্রদানকারীর শংসাপত্র লিঙ্ক করে একাধিক প্রমাণীকরণ প্রদানকারী ব্যবহার করে ব্যবহারকারীদের আপনার অ্যাপে সাইন ইন করার অনুমতি দিতে পারেন।

একজন ব্যবহারকারীকে সাইন আউট করতে, signOut কল করুন:

Web

import { getAuth, signOut } from "firebase/auth";

const auth = getAuth();
signOut(auth).then(() => {
  // Sign-out successful.
}).catch((error) => {
  // An error happened.
});

Web

firebase.auth().signOut().then(() => {
  // Sign-out successful.
}).catch((error) => {
  // An error happened.
});
,

এন্ড-টু-এন্ড OAuth 2.0 সাইন-ইন ফ্লো চালানোর জন্য আপনি Firebase SDK ব্যবহার করে আপনার ব্যবহারকারীদের তাদের Apple ID ব্যবহার করে Firebase-এর সাথে প্রমাণীকরণ করতে দিতে পারেন।

আপনি শুরু করার আগে

Apple ব্যবহার করে ব্যবহারকারীদের সাইন ইন করতে, প্রথমে Apple এর বিকাশকারী সাইটে Apple এর সাথে সাইন ইন কনফিগার করুন, তারপর আপনার Firebase প্রকল্পের জন্য একটি সাইন-ইন প্রদানকারী হিসাবে Apple সক্ষম করুন৷

অ্যাপল ডেভেলপার প্রোগ্রামে যোগ দিন

Apple এর সাথে সাইন ইন শুধুমাত্র Apple বিকাশকারী প্রোগ্রামের সদস্যদের দ্বারা কনফিগার করা যেতে পারে৷

অ্যাপল দিয়ে সাইন ইন কনফিগার করুন

অ্যাপল বিকাশকারী সাইটে, নিম্নলিখিতগুলি করুন:

  1. ওয়েবের জন্য Apple এর সাথে কনফিগার সাইন ইনের প্রথম বিভাগে বর্ণিত হিসাবে আপনার অ্যাপের সাথে আপনার ওয়েবসাইট যুক্ত করুন৷ অনুরোধ করা হলে, একটি রিটার্ন ইউআরএল হিসাবে নিম্নলিখিত URL নিবন্ধন করুন:

    https://YOUR_FIREBASE_PROJECT_ID.firebaseapp.com/__/auth/handler

    আপনি Firebase কনসোল সেটিংস পৃষ্ঠায় আপনার Firebase প্রকল্প আইডি পেতে পারেন।

    আপনার হয়ে গেলে, আপনার নতুন পরিষেবা আইডি নোট করুন, যা আপনাকে পরবর্তী বিভাগে প্রয়োজন হবে৷

  2. অ্যাপল ব্যক্তিগত কী দিয়ে একটি সাইন ইন তৈরি করুন । পরবর্তী বিভাগে আপনার নতুন ব্যক্তিগত কী এবং কী আইডির প্রয়োজন হবে৷
  3. আপনি যদি Firebase Authentication কোনো বৈশিষ্ট্য ব্যবহার করেন যা ব্যবহারকারীদের ইমেল পাঠায়, যার মধ্যে ইমেল লিঙ্ক সাইন-ইন, ইমেল ঠিকানা যাচাইকরণ, অ্যাকাউন্ট পরিবর্তন প্রত্যাহার, এবং অন্যান্য সহ, Apple প্রাইভেট ইমেল রিলে পরিষেবা কনফিগার করুন এবং noreply@ YOUR_FIREBASE_PROJECT_ID .firebaseapp.com (বা আপনার কাস্টমাইজড ইমেল টেমপ্লেট দ্বারা অ্যাপল ইমেল Firebase Authentication পাঠানোর জন্য অ্যাপল ব্যক্তিগত ইমেল রিলে পরিষেবা কনফিগার করুন) বেনামী অ্যাপল ইমেল ঠিকানায়.

একটি সাইন-ইন প্রদানকারী হিসাবে Apple সক্ষম করুন৷

  1. Add Firebase to your project .
  2. Firebase কনসোলে , Auth বিভাগটি খুলুন। সাইন ইন পদ্ধতি ট্যাবে, অ্যাপল প্রদানকারী সক্ষম করুন। পূর্ববর্তী বিভাগে আপনি যে পরিষেবা আইডি তৈরি করেছেন তা উল্লেখ করুন। এছাড়াও, OAuth কোড ফ্লো কনফিগারেশন বিভাগে , আপনার Apple টিম আইডি এবং পূর্ববর্তী বিভাগে আপনার তৈরি করা ব্যক্তিগত কী এবং কী আইডি উল্লেখ করুন।

অ্যাপল বেনামী ডেটা প্রয়োজনীয়তা মেনে চলুন

অ্যাপলের সাথে সাইন ইন ব্যবহারকারীদের সাইন ইন করার সময় তাদের ইমেল ঠিকানা সহ তাদের ডেটা বেনামী করার বিকল্প দেয়৷ যে ব্যবহারকারীরা এই বিকল্পটি বেছে নেন তাদের কাছে privaterelay.appleid.com ডোমেনের ইমেল ঠিকানা রয়েছে৷ আপনি যখন আপনার অ্যাপে Apple এর সাথে সাইন ইন ব্যবহার করেন, তখন আপনাকে অবশ্যই এই বেনামী Apple ID সংক্রান্ত যেকোন প্রযোজ্য বিকাশকারী নীতি বা Apple থেকে শর্তাবলী মেনে চলতে হবে।

আপনি একটি বেনামী অ্যাপল আইডির সাথে সরাসরি সনাক্তকারী ব্যক্তিগত তথ্য সংযুক্ত করার আগে যেকোন প্রয়োজনীয় ব্যবহারকারীর সম্মতি প্রাপ্ত করা এর মধ্যে রয়েছে। ফায়ারবেস প্রমাণীকরণ ব্যবহার করার সময়, এতে নিম্নলিখিত ক্রিয়াগুলি অন্তর্ভুক্ত থাকতে পারে:

  • একটি বেনামী অ্যাপল আইডি বা বিপরীতে একটি ইমেল ঠিকানা লিঙ্ক করুন.
  • একটি বেনামী অ্যাপল আইডিতে একটি ফোন নম্বর লিঙ্ক করুন বা এর বিপরীতে
  • একটি বেনামী সামাজিক শংসাপত্র (ফেসবুক, গুগল, ইত্যাদি) একটি বেনামী অ্যাপল আইডিতে বা এর বিপরীতে লিঙ্ক করুন৷

উপরের তালিকাটি সম্পূর্ণ নয়। আপনার অ্যাপ অ্যাপলের প্রয়োজনীয়তা পূরণ করছে তা নিশ্চিত করতে আপনার ডেভেলপার অ্যাকাউন্টের সদস্যপদ বিভাগে অ্যাপল ডেভেলপার প্রোগ্রাম লাইসেন্স চুক্তি পড়ুন।

Firebase SDK দিয়ে সাইন-ইন ফ্লো পরিচালনা করুন

আপনি যদি একটি ওয়েব অ্যাপ তৈরি করেন, তাহলে আপনার ব্যবহারকারীদের Firebase-এর মাধ্যমে তাদের Apple অ্যাকাউন্ট ব্যবহার করে প্রমাণীকরণ করার সবচেয়ে সহজ উপায় হল Firebase JavaScript SDK-এর মাধ্যমে সম্পূর্ণ সাইন-ইন প্রবাহ পরিচালনা করা।

Firebase JavaScript SDK দিয়ে সাইন-ইন প্রবাহ পরিচালনা করতে, এই ধাপগুলি অনুসরণ করুন:

  1. সংশ্লিষ্ট প্রদানকারী আইডি apple.com ব্যবহার করে একটি OAuthProvider- এর একটি উদাহরণ তৈরি করুন।

    Web

    import { OAuthProvider } from "firebase/auth";
    
    const provider = new OAuthProvider('apple.com');

    Web

    var provider = new firebase.auth.OAuthProvider('apple.com');
  2. ঐচ্ছিক: ডিফল্টের বাইরে অতিরিক্ত OAuth 2.0 স্কোপ নির্দিষ্ট করুন যা আপনি প্রমাণীকরণ প্রদানকারীর কাছ থেকে অনুরোধ করতে চান।

    Web

    provider.addScope('email');
    provider.addScope('name');

    Web

    provider.addScope('email');
    provider.addScope('name');

    ডিফল্টরূপে, যখন প্রতি ইমেল ঠিকানায় একটি অ্যাকাউন্ট সক্রিয় থাকে, তখন Firebase ইমেল এবং নামের সুযোগের অনুরোধ করে। আপনি যদি এই সেটিংটি প্রতি ইমেল ঠিকানায় একাধিক অ্যাকাউন্টে পরিবর্তন করেন, তাহলে Firebase অ্যাপল থেকে কোনো সুযোগের অনুরোধ করে না যদি না আপনি সেগুলি নির্দিষ্ট করেন।

  3. ঐচ্ছিক: আপনি যদি ইংরেজি ছাড়া অন্য কোনো ভাষায় Apple-এর সাইন-ইন স্ক্রীন প্রদর্শন করতে চান, তাহলে locale প্যারামিটার সেট করুন। সমর্থিত লোকেলের জন্য অ্যাপল ডক্স দিয়ে সাইন ইন দেখুন।

    Web

    provider.setCustomParameters({
      // Localize the Apple authentication screen in French.
      locale: 'fr'
    });

    Web

    provider.setCustomParameters({
      // Localize the Apple authentication screen in French.
      locale: 'fr'
    });
  4. OAuth প্রদানকারী অবজেক্ট ব্যবহার করে Firebase দিয়ে প্রমাণীকরণ করুন। আপনি আপনার ব্যবহারকারীদের একটি পপ-আপ উইন্ডো খোলার মাধ্যমে বা সাইন-ইন পৃষ্ঠায় পুনঃনির্দেশিত করে তাদের Apple অ্যাকাউন্টগুলির সাথে সাইন ইন করতে অনুরোধ করতে পারেন৷ রিডাইরেক্ট পদ্ধতি মোবাইল ডিভাইসে পছন্দ করা হয়।

    • একটি পপ-আপ উইন্ডো দিয়ে সাইন ইন করতে, signInWithPopup() কল করুন :

      Web

      import { getAuth, signInWithPopup, OAuthProvider } from "firebase/auth";
      
      const auth = getAuth();
      signInWithPopup(auth, provider)
        .then((result) => {
          // The signed-in user info.
          const user = result.user;
      
          // Apple credential
          const credential = OAuthProvider.credentialFromResult(result);
          const accessToken = credential.accessToken;
          const idToken = credential.idToken;
      
          // IdP data available using getAdditionalUserInfo(result)
          // ...
        })
        .catch((error) => {
          // Handle Errors here.
          const errorCode = error.code;
          const errorMessage = error.message;
          // The email of the user's account used.
          const email = error.customData.email;
          // The credential that was used.
          const credential = OAuthProvider.credentialFromError(error);
      
          // ...
        });

      Web

      firebase
        .auth()
        .signInWithPopup(provider)
        .then((result) => {
          /** @type {firebase.auth.OAuthCredential} */
          var credential = result.credential;
      
          // The signed-in user info.
          var user = result.user;
      
          // You can also get the Apple OAuth Access and ID Tokens.
          var accessToken = credential.accessToken;
          var idToken = credential.idToken;
      
          // IdP data available using getAdditionalUserInfo(result)
        // ...
        })
        .catch((error) => {
          // Handle Errors here.
          var errorCode = error.code;
          var errorMessage = error.message;
          // The email of the user's account used.
          var email = error.email;
          // The firebase.auth.AuthCredential type that was used.
          var credential = error.credential;
      
          // ...
        });
    • সাইন-ইন পৃষ্ঠায় পুনঃনির্দেশ করে সাইন ইন করতে, signInWithRedirect() কল করুন :

    signInWithRedirect , linkWithRedirect , অথবা reauthenticateWithRedirect ব্যবহার করার সময় সর্বোত্তম অনুশীলনগুলি অনুসরণ করুন৷

    Web

    import { getAuth, signInWithRedirect } from "firebase/auth";
    
    const auth = getAuth();
    signInWithRedirect(auth, provider);

    Web

    firebase.auth().signInWithRedirect(provider);

    ব্যবহারকারী সাইন-ইন সম্পূর্ণ করার পরে এবং পৃষ্ঠায় ফিরে আসার পরে, আপনি getRedirectResult() কল করে সাইন-ইন ফলাফল পেতে পারেন :

    Web

    import { getAuth, getRedirectResult, OAuthProvider } from "firebase/auth";
    
    // Result from Redirect auth flow.
    const auth = getAuth();
    getRedirectResult(auth)
      .then((result) => {
        const credential = OAuthProvider.credentialFromResult(result);
        if (credential) {
          // You can also get the Apple OAuth Access and ID Tokens.
          const accessToken = credential.accessToken;
          const idToken = credential.idToken;
        }
        // The signed-in user info.
        const user = result.user;
      })
      .catch((error) => {
        // Handle Errors here.
        const errorCode = error.code;
        const errorMessage = error.message;
        // The email of the user's account used.
        const email = error.customData.email;
        // The credential that was used.
        const credential = OAuthProvider.credentialFromError(error);
    
        // ...
      });

    Web

    // Result from Redirect auth flow.
    firebase
      .auth()
      .getRedirectResult()
      .then((result) => {
        if (result.credential) {
          /** @type {firebase.auth.OAuthCredential} */
          var credential = result.credential;
    
          // You can get the Apple OAuth Access and ID Tokens.
          var accessToken = credential.accessToken;
          var idToken = credential.idToken;
    
          // IdP data available in result.additionalUserInfo.profile.
          // ...
        }
        // The signed-in user info.
        var user = result.user;
      })
      .catch((error) => {
        // Handle Errors here.
        var errorCode = error.code;
        var errorMessage = error.message;
        // The email of the user's account used.
        var email = error.email;
        // The firebase.auth.AuthCredential type that was used.
        var credential = error.credential;
    
        // ...
      });

    এটিও যেখানে আপনি ত্রুটিগুলি ধরতে এবং পরিচালনা করতে পারেন৷ ত্রুটি কোডের একটি তালিকার জন্য, API রেফারেন্স দেখুন।

    Firebase Auth দ্বারা সমর্থিত অন্যান্য প্রদানকারীদের থেকে ভিন্ন, Apple একটি ফটো URL প্রদান করে না।

    এছাড়াও, ব্যবহারকারী যখন অ্যাপের সাথে তাদের ইমেল শেয়ার না করা বেছে নেয়, তখন অ্যাপল সেই ব্যবহারকারীর জন্য একটি অনন্য ইমেল ঠিকানার ব্যবস্থা করে (ফর্ম xyz@privaterelay.appleid.com ), যা এটি আপনার অ্যাপের সাথে শেয়ার করে। আপনি যদি ব্যক্তিগত ইমেল রিলে পরিষেবা কনফিগার করেন, অ্যাপল ব্যবহারকারীর আসল ইমেল ঠিকানায় বেনামী ঠিকানায় পাঠানো ইমেলগুলি ফরওয়ার্ড করে।

    অ্যাপল শুধুমাত্র ব্যবহারকারীর তথ্য শেয়ার করে যেমন ডিসপ্লে নাম অ্যাপের সাথে প্রথমবার যখন কোনো ব্যবহারকারী সাইন ইন করে। সাধারণত, Firebase ডিসপ্লে নাম সংরক্ষণ করে যখন কোনো ব্যবহারকারী অ্যাপলের সাথে সাইন ইন করে, যা আপনি firebase.auth().currentUser.displayName মাধ্যমে পেতে পারেন। যাইহোক, আপনি যদি আগে Firebase ব্যবহার না করে অ্যাপে কোনো ব্যবহারকারীকে সাইন ইন করার জন্য Apple ব্যবহার করেন, তাহলে Apple ব্যবহারকারীর প্রদর্শনের নাম দিয়ে Firebase প্রদান করবে না।

পুনরায় প্রমাণীকরণ এবং অ্যাকাউন্ট লিঙ্কিং

একই প্যাটার্নটি reauthenticateWithPopup() এবং reauthenticateWithRedirect() এর সাথে ব্যবহার করা যেতে পারে, যা আপনি সাম্প্রতিক সাইন-ইন প্রয়োজন এমন সংবেদনশীল অপারেশনগুলির জন্য একটি নতুন শংসাপত্র পুনরুদ্ধার করতে ব্যবহার করতে পারেন:

Web

import { getAuth, reauthenticateWithPopup, OAuthProvider } from "firebase/auth";

// Result from Redirect auth flow.
const auth = getAuth();
const provider = new OAuthProvider('apple.com');

reauthenticateWithPopup(auth.currentUser, provider)
  .then((result) => {
    // User is re-authenticated with fresh tokens minted and can perform
    // sensitive operations like account deletion, or updating their email
    // address or password.

    // The signed-in user info.
    const user = result.user;

    // You can also get the Apple OAuth Access and ID Tokens.
    const credential = OAuthProvider.credentialFromResult(result);
    const accessToken = credential.accessToken;
    const idToken = credential.idToken;

    // ...
  })
  .catch((error) => {
    // Handle Errors here.
    const errorCode = error.code;
    const errorMessage = error.message;
    // The email of the user's account used.
    const email = error.customData.email;
    // The credential that was used.
    const credential = OAuthProvider.credentialFromError(error);

    // ...
  });

Web

const provider = new firebase.auth.OAuthProvider('apple.com');

firebase
  .auth()
  .currentUser
  .reauthenticateWithPopup(provider)
  .then((result) => {
    // User is re-authenticated with fresh tokens minted and can perform
    // sensitive operations like account deletion, or updating their email
    // address or password.
    /** @type {firebase.auth.OAuthCredential} */
    var credential = result.credential;

    // The signed-in user info.
    var user = result.user;
     // You can also get the Apple OAuth Access and ID Tokens.
    var accessToken = credential.accessToken;
    var idToken = credential.idToken;

    // IdP data available in result.additionalUserInfo.profile.
      // ...
  })
  .catch((error) => {
    // Handle Errors here.
    var errorCode = error.code;
    var errorMessage = error.message;
    // The email of the user's account used.
    var email = error.email;
    // The firebase.auth.AuthCredential type that was used.
    var credential = error.credential;

    // ...
  });

এবং, আপনি বিদ্যমান অ্যাকাউন্টে বিভিন্ন পরিচয় প্রদানকারীকে লিঙ্ক করতে linkWithPopup() এবং linkWithRedirect() ব্যবহার করতে পারেন।

মনে রাখবেন যে অ্যাপল আপনাকে তাদের অ্যাপল অ্যাকাউন্টগুলিকে অন্য ডেটার সাথে লিঙ্ক করার আগে ব্যবহারকারীদের কাছ থেকে স্পষ্ট সম্মতি নিতে হবে।

উদাহরণস্বরূপ, বর্তমান ফায়ারবেস অ্যাকাউন্টের সাথে একটি Facebook অ্যাকাউন্ট লিঙ্ক করতে, ব্যবহারকারীকে Facebook-এ সাইন ইন করার সময় আপনি যে অ্যাক্সেস টোকেন পেয়েছেন তা ব্যবহার করুন:

Web

import { getAuth, linkWithPopup, FacebookAuthProvider } from "firebase/auth";

const auth = getAuth();
const provider = new FacebookAuthProvider();
provider.addScope('user_birthday');

// Assuming the current user is an Apple user linking a Facebook provider.
linkWithPopup(auth.currentUser, provider)
    .then((result) => {
      // Facebook credential is linked to the current Apple user.
      // ...

      // The user can now sign in to the same account
      // with either Apple or Facebook.
    })
    .catch((error) => {
      // Handle error.
    });

Web

const provider = new firebase.auth.FacebookAuthProvider();
provider.addScope('user_birthday');

// Assuming the current user is an Apple user linking a Facebook provider.
firebase.auth().currentUser.linkWithPopup(provider)
    .then((result) => {
      // Facebook credential is linked to the current Apple user.
      // Facebook additional data available in result.additionalUserInfo.profile,

      // Additional Facebook OAuth access token can also be retrieved.
      // result.credential.accessToken

      // The user can now sign in to the same account
      // with either Apple or Facebook.
    })
    .catch((error) => {
      // Handle error.
    });

একটি Chrome এক্সটেনশনে Firebase দিয়ে প্রমাণীকরণ করুন

আপনি যদি একটি Chrome এক্সটেনশন অ্যাপ তৈরি করেন, অফস্ক্রিন ডকুমেন্টস গাইড দেখুন।

মনে রাখবেন যে আপনাকে এখনও Apple-এর সাথে ডিফল্ট firebaseapp.com ডোমেনের মতোই কাস্টম ডোমেন যাচাই করতে হবে:

http://auth.custom.example.com/.well-known/apple-developer-domain-association.txt

টোকেন প্রত্যাহার

অ্যাপলের প্রয়োজন যে অ্যাপগুলি অ্যাকাউন্ট তৈরিকে সমর্থন করে সেগুলিকে অবশ্যই ব্যবহারকারীদের অ্যাপের মধ্যে তাদের অ্যাকাউন্ট মুছে ফেলা শুরু করতে দিতে হবে, যেমন অ্যাপ স্টোর পর্যালোচনা নির্দেশিকাতে বর্ণিত হয়েছে

এই প্রয়োজনীয়তা পূরণ করতে, নিম্নলিখিত পদক্ষেপগুলি বাস্তবায়ন করুন:

  1. নিশ্চিত করুন যে আপনি অ্যাপল প্রদানকারী কনফিগারেশনের সাথে সাইন ইন-এর পরিষেবা আইডি এবং OAuth কোড ফ্লো কনফিগারেশন বিভাগটি পূরণ করেছেন, যেমনটি অ্যাপলের সাথে সাইন ইন কনফিগার করুন বিভাগে বর্ণিত হয়েছে।

  2. যেহেতু Firebase ব্যবহারকারীর টোকেন সংরক্ষণ করে না যখন ব্যবহারকারীরা অ্যাপলের সাথে সাইন ইন করে তৈরি করা হয়, তাই আপনাকে অবশ্যই ব্যবহারকারীকে তাদের টোকেন প্রত্যাহার এবং অ্যাকাউন্ট মুছে ফেলার আগে আবার সাইন ইন করতে বলতে হবে।

    তারপর, OAuthCredential থেকে Apple OAuth অ্যাক্সেস টোকেনটি পান এবং Apple OAuth অ্যাক্সেস টোকেন প্রত্যাহার করতে revokeAccessToken(auth, token) কল করতে এটি ব্যবহার করুন৷

    const provider = new OAuthProvider('apple.com');
    provider.addScope('email');
    provider.addScope('name');
    
    const auth = getAuth();
    signInWithPopup(auth, provider).then(result => {
      // Get the Apple OAuth access token.
      const credential = OAuthProvider.credentialFromResult(result);
      const accessToken = credential.accessToken;
    
      // Revoke the Apple OAuth access token.
      revokeAccessToken(auth, accessToken)
        .then(() => {
          // Token revoked.
    
          // Delete the user account.
          // ...
        })
        .catch(error => {
          // An error happened.
          // ...
        });
    });
    
  3. অবশেষে, ব্যবহারকারীর অ্যাকাউন্ট (এবং সমস্ত সম্পর্কিত ডেটা) মুছুন

উন্নত: Node.js-এ Firebase দিয়ে প্রমাণীকরণ করুন

একটি Node.js অ্যাপ্লিকেশনে ফায়ারবেসের সাথে প্রমাণীকরণ করতে:

  1. ব্যবহারকারীকে তাদের অ্যাপল অ্যাকাউন্ট দিয়ে সাইন ইন করুন এবং ব্যবহারকারীর অ্যাপল আইডি টোকেন পান। আপনি এটি বিভিন্ন উপায়ে সম্পন্ন করতে পারেন। উদাহরণস্বরূপ, যদি আপনার Node.js অ্যাপের একটি ব্রাউজার ফ্রন্ট এন্ড থাকে:

    1. আপনার ব্যাকএন্ডে, একটি এলোমেলো স্ট্রিং তৈরি করুন (একটি "নন্স") এবং এর SHA256 হ্যাশ গণনা করুন। ননস হল একটি এককালীন ব্যবহারের মান যা আপনি আপনার ব্যাকএন্ড এবং Apple এর প্রমাণীকরণ সার্ভারগুলির মধ্যে একটি একক রাউন্ড ট্রিপ যাচাই করতে ব্যবহার করেন৷

      Web

      const crypto = require("crypto");
      const string_decoder = require("string_decoder");
      
      // Generate a new random string for each sign-in
      const generateNonce = (length) => {
        const decoder = new string_decoder.StringDecoder("ascii");
        const buf = Buffer.alloc(length);
        let nonce = "";
        while (nonce.length < length) {
          crypto.randomFillSync(buf);
          nonce = decoder.write(buf);
        }
        return nonce.slice(0, length);
      };
      
      const unhashedNonce = generateNonce(10);
      
      // SHA256-hashed nonce in hex
      const hashedNonceHex = crypto.createHash('sha256')
        .update(unhashedNonce).digest().toString('hex');

      Web

      const crypto = require("crypto");
      const string_decoder = require("string_decoder");
      
      // Generate a new random string for each sign-in
      const generateNonce = function(length) {
        const decoder = new string_decoder.StringDecoder("ascii");
        const buf = Buffer.alloc(length);
        var nonce = "";
        while (nonce.length < length) {
          crypto.randomFillSync(buf);
          nonce = decoder.write(buf);
        }
        return nonce.slice(0, length);
      };
      
      const unhashedNonce = generateNonce(10);
      
      // SHA256-hashed nonce in hex
      const hashedNonceHex = crypto.createHash('sha256')
        .update(unhashedNonce).digest().toString('hex');
    2. আপনার সাইন-ইন পৃষ্ঠায়, অ্যাপল কনফিগারেশনের সাথে আপনার সাইন ইনে হ্যাশড ননস উল্লেখ করুন:

      <script src="https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js"></script>
      <div id="appleid-signin" data-color="black" data-border="true" data-type="sign in"></div>
      <script>
          AppleID.auth.init({
              clientId: YOUR_APPLE_CLIENT_ID,
              scope: 'name email',
              redirectURI: URL_TO_YOUR_REDIRECT_HANDLER,  // See the next step.
              state: '[STATE]',  // Optional value that Apple will send back to you
                                 // so you can return users to the same context after
                                 // they sign in.
              nonce: HASHED_NONCE  // The hashed nonce you generated in the previous step.
          });
      </script>
      
    3. পোস্ট করা প্রমাণীকরণ প্রতিক্রিয়া সার্ভার-সাইড থেকে অ্যাপল আইডি টোকেন পান:

      app.post('/redirect', (req, res) => {
        const savedState = req.cookies.__session;
        const code = req.body.code;
        const state = req.body.state;
        const appleIdToken = req.body.id_token;
        if (savedState !== state || !code) {
          res.status(403).send('403: Permission denied');
        } else {
          // Sign in with Firebase using appleIdToken. (See next step).
        }
      });
      

    এছাড়াও অ্যাপলের সাথে সাইন ইন করার জন্য আপনার ওয়েবপৃষ্ঠা কনফিগার করা দেখুন।

  2. আপনি ব্যবহারকারীর অ্যাপল আইডি টোকেন পাওয়ার পরে, একটি শংসাপত্র বস্তু তৈরি করতে এটি ব্যবহার করুন এবং তারপরে শংসাপত্রের সাথে ব্যবহারকারীকে সাইন ইন করুন:

    Web

    import { getAuth, signInWithCredential, OAuthProvider } from "firebase/auth";
    
    const auth = getAuth();
    
    // Build Firebase credential with the Apple ID token.
    const provider = new OAuthProvider('apple.com');
    const authCredential = provider.credential({
      idToken: appleIdToken,
      rawNonce: unhashedNonce,
    });
    
    // Sign in with credential form the Apple user.
    signInWithCredential(auth, authCredential)
      .then((result) => {
        // User signed in.
      })
      .catch((error) => {
        // An error occurred. If error.code == 'auth/missing-or-invalid-nonce',
        // make sure you're sending the SHA256-hashed nonce as a hex string
        // with your request to Apple.
        console.log(error);
      });

    Web

    // Build Firebase credential with the Apple ID token.
    const provider = new firebase.auth.OAuthProvider('apple.com');
    const authCredential = provider.credential({
      idToken: appleIdToken,
      rawNonce: unhashedNonce,
    });
    
    // Sign in with credential form the Apple user.
    firebase.auth().signInWithCredential(authCredential)
      .then((result) => {
        // User signed in.
      })
      .catch((error) => {
        // An error occurred. If error.code == 'auth/missing-or-invalid-nonce',
        // make sure you're sending the SHA256-hashed nonce as a hex string
        // with your request to Apple.
        console.log(error);
      });

পরবর্তী পদক্ষেপ

একজন ব্যবহারকারী প্রথমবার সাইন ইন করার পরে, একটি নতুন ব্যবহারকারীর অ্যাকাউন্ট তৈরি করা হয় এবং শংসাপত্রগুলির সাথে লিঙ্ক করা হয়—অর্থাৎ, ব্যবহারকারীর নাম এবং পাসওয়ার্ড, ফোন নম্বর, বা প্রমাণ প্রদানকারীর তথ্য — ব্যবহারকারী সাইন ইন করেছেন। এই নতুন অ্যাকাউন্টটি আপনার ফায়ারবেস প্রকল্পের অংশ হিসাবে সংরক্ষণ করা হয়েছে এবং ব্যবহারকারী কীভাবে সাইন ইন করুন না কেন, আপনার প্রকল্পের প্রতিটি অ্যাপ জুড়ে একজন ব্যবহারকারীকে শনাক্ত করতে ব্যবহার করা যেতে পারে।

  • আপনার অ্যাপে, আপনার ব্যবহারকারীর প্রমাণীকরণের স্থিতি জানার প্রস্তাবিত উপায় হল Auth অবজেক্টে একজন পর্যবেক্ষক সেট করা। তারপর আপনি User অবজেক্ট থেকে ব্যবহারকারীর মৌলিক প্রোফাইল তথ্য পেতে পারেন। ব্যবহারকারীদের পরিচালনা দেখুন।

  • আপনার Firebase Realtime Database এবং Cloud Storage সুরক্ষা নিয়মে , আপনি auth ভেরিয়েবল থেকে সাইন-ইন করা ব্যবহারকারীর অনন্য ব্যবহারকারী আইডি পেতে পারেন এবং ব্যবহারকারী কোন ডেটা অ্যাক্সেস করতে পারে তা নিয়ন্ত্রণ করতে এটি ব্যবহার করতে পারেন।

আপনি একটি বিদ্যমান ব্যবহারকারীর অ্যাকাউন্টে প্রমাণীকরণ প্রদানকারীর শংসাপত্র লিঙ্ক করে একাধিক প্রমাণীকরণ প্রদানকারী ব্যবহার করে ব্যবহারকারীদের আপনার অ্যাপে সাইন ইন করার অনুমতি দিতে পারেন।

একজন ব্যবহারকারীকে সাইন আউট করতে, signOut কল করুন:

Web

import { getAuth, signOut } from "firebase/auth";

const auth = getAuth();
signOut(auth).then(() => {
  // Sign-out successful.
}).catch((error) => {
  // An error happened.
});

Web

firebase.auth().signOut().then(() => {
  // Sign-out successful.
}).catch((error) => {
  // An error happened.
});
,

এন্ড-টু-এন্ড OAuth 2.0 সাইন-ইন ফ্লো চালানোর জন্য আপনি Firebase SDK ব্যবহার করে আপনার ব্যবহারকারীদের তাদের Apple ID ব্যবহার করে Firebase-এর সাথে প্রমাণীকরণ করতে দিতে পারেন।

আপনি শুরু করার আগে

Apple ব্যবহার করে ব্যবহারকারীদের সাইন ইন করতে, প্রথমে Apple এর বিকাশকারী সাইটে Apple এর সাথে সাইন ইন কনফিগার করুন, তারপর আপনার Firebase প্রকল্পের জন্য একটি সাইন-ইন প্রদানকারী হিসাবে Apple সক্ষম করুন৷

অ্যাপল ডেভেলপার প্রোগ্রামে যোগ দিন

Apple এর সাথে সাইন ইন শুধুমাত্র Apple বিকাশকারী প্রোগ্রামের সদস্যদের দ্বারা কনফিগার করা যেতে পারে৷

অ্যাপল দিয়ে সাইন ইন কনফিগার করুন

অ্যাপল বিকাশকারী সাইটে, নিম্নলিখিতগুলি করুন:

  1. ওয়েবের জন্য Apple এর সাথে কনফিগার সাইন ইনের প্রথম বিভাগে বর্ণিত হিসাবে আপনার অ্যাপের সাথে আপনার ওয়েবসাইট যুক্ত করুন৷ অনুরোধ করা হলে, একটি রিটার্ন ইউআরএল হিসাবে নিম্নলিখিত URL নিবন্ধন করুন:

    https://YOUR_FIREBASE_PROJECT_ID.firebaseapp.com/__/auth/handler

    আপনি Firebase কনসোল সেটিংস পৃষ্ঠায় আপনার Firebase প্রকল্প আইডি পেতে পারেন।

    আপনার হয়ে গেলে, আপনার নতুন পরিষেবা আইডি নোট করুন, যা আপনাকে পরবর্তী বিভাগে প্রয়োজন হবে৷

  2. অ্যাপল ব্যক্তিগত কী দিয়ে একটি সাইন ইন তৈরি করুন । পরবর্তী বিভাগে আপনার নতুন ব্যক্তিগত কী এবং কী আইডির প্রয়োজন হবে৷
  3. আপনি যদি Firebase Authentication এমন কোনও বৈশিষ্ট্য ব্যবহার করেন যা ব্যবহারকারীদের ইমেল প্রেরণ করে, ইমেল লিঙ্ক সাইন-ইন, ইমেল ঠিকানা যাচাইকরণ, অ্যাকাউন্ট পরিবর্তন প্রত্যাহার এবং অন্যদের সহ, অ্যাপল প্রাইভেট ইমেল রিলে পরিষেবাটি কনফিগার করুন এবং noreply@ YOUR_FIREBASE_PROJECT_ID .firebaseapp.com Firebase Authentication অ্যাপল ইমেল ঠিকানা বেনামে।

অ্যাপলকে সাইন-ইন সরবরাহকারী হিসাবে সক্ষম করুন

  1. আপনার প্রকল্পে ফায়ারবেস যুক্ত করুন
  2. Firebase কনসোলে , প্রমাণ বিভাগটি খুলুন। সাইন ইন পদ্ধতি ট্যাবে, অ্যাপল সরবরাহকারীকে সক্ষম করুন। আপনি পূর্ববর্তী বিভাগে তৈরি পরিষেবা আইডি নির্দিষ্ট করুন। এছাড়াও, OAuth কোড ফ্লো কনফিগারেশন বিভাগে , আপনার অ্যাপল টিম আইডি এবং আপনি পূর্ববর্তী বিভাগে তৈরি করা ব্যক্তিগত কী এবং কী আইডি নির্দিষ্ট করুন।

অ্যাপল বেনামে ডেটা প্রয়োজনীয়তা মেনে চলুন

অ্যাপলের সাথে সাইন ইন করা ব্যবহারকারীদের সাইন ইন করার সময় তাদের ইমেল ঠিকানা সহ তাদের ডেটা বেনামে দেওয়ার বিকল্প দেয় users এই বিকল্পটি বেছে নেওয়া ব্যবহারকারীরা ডোমেন privaterelay.appleid.com সাথে ইমেল ঠিকানা রয়েছে। আপনি যখন আপনার অ্যাপে অ্যাপলের সাথে সাইন ইন ব্যবহার করেন, আপনাকে অবশ্যই এই বেনামে অ্যাপল আইডি সম্পর্কিত অ্যাপল থেকে কোনও প্রযোজ্য বিকাশকারী নীতি বা শর্তাদি মেনে চলতে হবে।

এর মধ্যে আপনি কোনও বেনামে অ্যাপল আইডির সাথে সরাসরি ব্যক্তিগত তথ্য সনাক্তকরণের সাথে সংযুক্ত করার আগে কোনও প্রয়োজনীয় ব্যবহারকারীর সম্মতি অর্জনের অন্তর্ভুক্ত। ফায়ারবেস প্রমাণীকরণ ব্যবহার করার সময়, এতে নিম্নলিখিত ক্রিয়াগুলি অন্তর্ভুক্ত থাকতে পারে:

  • একটি বেনামে অ্যাপল আইডি বা এর বিপরীতে একটি ইমেল ঠিকানা লিঙ্ক করুন।
  • একটি ফোন নম্বর একটি বেনামে অ্যাপল আইডি বা তদ্বিপরীতের সাথে লিঙ্ক করুন
  • একটি অজ্ঞাত সামাজিক শংসাপত্র (ফেসবুক, গুগল, ইত্যাদি) একটি বেনামে অ্যাপল আইডিতে বা তদ্বিপরীতের সাথে লিঙ্ক করুন।

উপরের তালিকাটি সম্পূর্ণ নয়। আপনার অ্যাপ্লিকেশন অ্যাপলের প্রয়োজনীয়তাগুলি পূরণ করে তা নিশ্চিত করতে আপনার বিকাশকারী অ্যাকাউন্টের সদস্যপদ বিভাগে অ্যাপল বিকাশকারী প্রোগ্রাম লাইসেন্স চুক্তিটি দেখুন।

ফায়ারবেস এসডিকে দিয়ে সাইন-ইন প্রবাহ পরিচালনা করুন

আপনি যদি কোনও ওয়েব অ্যাপ্লিকেশন তৈরি করছেন তবে আপনার ব্যবহারকারীদের তাদের অ্যাপল অ্যাকাউন্টগুলি ব্যবহার করে ফায়ারবেস দিয়ে প্রমাণীকরণের সহজতম উপায় হ'ল ফায়ারবেস জাভাস্ক্রিপ্ট এসডিকে দিয়ে পুরো সাইন-ইন প্রবাহটি পরিচালনা করা।

ফায়ারবেস জাভাস্ক্রিপ্ট এসডিকে দিয়ে সাইন-ইন প্রবাহ পরিচালনা করতে, এই পদক্ষেপগুলি অনুসরণ করুন:

  1. সংশ্লিষ্ট সরবরাহকারী আইডি অ্যাপল ডটকম ব্যবহার করে কোনও OAuthProvider এর উদাহরণ তৈরি করুন।

    Web

    import { OAuthProvider } from "firebase/auth";
    
    const provider = new OAuthProvider('apple.com');

    Web

    var provider = new firebase.auth.OAuthProvider('apple.com');
  2. Ption চ্ছিক: আপনি প্রমাণীকরণ সরবরাহকারীর কাছ থেকে অনুরোধ করতে চান এমন ডিফল্ট ছাড়িয়ে অতিরিক্ত OAuth 2.0 স্কোপগুলি নির্দিষ্ট করুন।

    Web

    provider.addScope('email');
    provider.addScope('name');

    Web

    provider.addScope('email');
    provider.addScope('name');

    ডিফল্টরূপে, যখন প্রতি ইমেল ঠিকানা প্রতি একটি অ্যাকাউন্ট সক্ষম করা থাকে, ফায়ারবেস ইমেল এবং নাম স্কোপগুলির জন্য অনুরোধ করে। আপনি যদি এই সেটিংটি প্রতি ইমেল ঠিকানা প্রতি একাধিক অ্যাকাউন্টে পরিবর্তন করেন তবে ফায়ারবেস অ্যাপল থেকে কোনও স্কোপের জন্য অনুরোধ করে না যদি আপনি সেগুলি নির্দিষ্ট না করে।

  3. Ption চ্ছিক: আপনি যদি ইংরেজি ব্যতীত অন্য কোনও ভাষায় অ্যাপলের সাইন-ইন স্ক্রিনটি প্রদর্শন করতে চান তবে locale প্যারামিটারটি সেট করুন। সমর্থিত লোকালগুলির জন্য অ্যাপল ডক্সের সাথে সাইন ইন দেখুন।

    Web

    provider.setCustomParameters({
      // Localize the Apple authentication screen in French.
      locale: 'fr'
    });

    Web

    provider.setCustomParameters({
      // Localize the Apple authentication screen in French.
      locale: 'fr'
    });
  4. OAuth সরবরাহকারী অবজেক্টটি ব্যবহার করে ফায়ারবেস দিয়ে প্রমাণীকরণ করুন। আপনি আপনার ব্যবহারকারীদের একটি পপ-আপ উইন্ডো খোলার মাধ্যমে বা সাইন-ইন পৃষ্ঠায় পুনর্নির্দেশ করে তাদের অ্যাপল অ্যাকাউন্টগুলির সাথে সাইন ইন করতে অনুরোধ করতে পারেন। পুনঃনির্দেশ পদ্ধতিটি মোবাইল ডিভাইসে পছন্দ করা হয়।

    • একটি পপ-আপ উইন্ডো দিয়ে সাইন ইন করতে, signInWithPopup() কল করুন:

      Web

      import { getAuth, signInWithPopup, OAuthProvider } from "firebase/auth";
      
      const auth = getAuth();
      signInWithPopup(auth, provider)
        .then((result) => {
          // The signed-in user info.
          const user = result.user;
      
          // Apple credential
          const credential = OAuthProvider.credentialFromResult(result);
          const accessToken = credential.accessToken;
          const idToken = credential.idToken;
      
          // IdP data available using getAdditionalUserInfo(result)
          // ...
        })
        .catch((error) => {
          // Handle Errors here.
          const errorCode = error.code;
          const errorMessage = error.message;
          // The email of the user's account used.
          const email = error.customData.email;
          // The credential that was used.
          const credential = OAuthProvider.credentialFromError(error);
      
          // ...
        });

      Web

      firebase
        .auth()
        .signInWithPopup(provider)
        .then((result) => {
          /** @type {firebase.auth.OAuthCredential} */
          var credential = result.credential;
      
          // The signed-in user info.
          var user = result.user;
      
          // You can also get the Apple OAuth Access and ID Tokens.
          var accessToken = credential.accessToken;
          var idToken = credential.idToken;
      
          // IdP data available using getAdditionalUserInfo(result)
        // ...
        })
        .catch((error) => {
          // Handle Errors here.
          var errorCode = error.code;
          var errorMessage = error.message;
          // The email of the user's account used.
          var email = error.email;
          // The firebase.auth.AuthCredential type that was used.
          var credential = error.credential;
      
          // ...
        });
    • সাইন-ইন পৃষ্ঠায় পুনর্নির্দেশ করে সাইন ইন করতে, signInWithRedirect() কল করুন:

    signInWithRedirect , linkWithRedirect , অথবা reauthenticateWithRedirect ব্যবহার করার সময় সর্বোত্তম অনুশীলনগুলি অনুসরণ করুন৷

    Web

    import { getAuth, signInWithRedirect } from "firebase/auth";
    
    const auth = getAuth();
    signInWithRedirect(auth, provider);

    Web

    firebase.auth().signInWithRedirect(provider);

    ব্যবহারকারী সাইন-ইন সম্পূর্ণ করে এবং পৃষ্ঠায় ফিরে আসার পরে, আপনি getRedirectResult() কল করে সাইন-ইন ফলাফল পেতে পারেন:

    Web

    import { getAuth, getRedirectResult, OAuthProvider } from "firebase/auth";
    
    // Result from Redirect auth flow.
    const auth = getAuth();
    getRedirectResult(auth)
      .then((result) => {
        const credential = OAuthProvider.credentialFromResult(result);
        if (credential) {
          // You can also get the Apple OAuth Access and ID Tokens.
          const accessToken = credential.accessToken;
          const idToken = credential.idToken;
        }
        // The signed-in user info.
        const user = result.user;
      })
      .catch((error) => {
        // Handle Errors here.
        const errorCode = error.code;
        const errorMessage = error.message;
        // The email of the user's account used.
        const email = error.customData.email;
        // The credential that was used.
        const credential = OAuthProvider.credentialFromError(error);
    
        // ...
      });

    Web

    // Result from Redirect auth flow.
    firebase
      .auth()
      .getRedirectResult()
      .then((result) => {
        if (result.credential) {
          /** @type {firebase.auth.OAuthCredential} */
          var credential = result.credential;
    
          // You can get the Apple OAuth Access and ID Tokens.
          var accessToken = credential.accessToken;
          var idToken = credential.idToken;
    
          // IdP data available in result.additionalUserInfo.profile.
          // ...
        }
        // The signed-in user info.
        var user = result.user;
      })
      .catch((error) => {
        // Handle Errors here.
        var errorCode = error.code;
        var errorMessage = error.message;
        // The email of the user's account used.
        var email = error.email;
        // The firebase.auth.AuthCredential type that was used.
        var credential = error.credential;
    
        // ...
      });

    এটিও যেখানে আপনি ত্রুটিগুলি ধরতে এবং পরিচালনা করতে পারেন। ত্রুটি কোডগুলির তালিকার জন্য, এপিআই রেফারেন্সটি দেখুন।

    ফায়ারবেস এথ দ্বারা সমর্থিত অন্যান্য সরবরাহকারীদের বিপরীতে, অ্যাপল কোনও ফটো ইউআরএল সরবরাহ করে না।

    এছাড়াও, যখন ব্যবহারকারী অ্যাপ্লিকেশনটির সাথে তাদের ইমেলটি ভাগ না করতে পছন্দ করেন, তখন অ্যাপল সেই ব্যবহারকারীর জন্য একটি অনন্য ইমেল ঠিকানা সরবরাহ করে (ফর্ম xyz@privaterelay.appleid.com ), যা এটি আপনার অ্যাপ্লিকেশনটির সাথে ভাগ করে। আপনি যদি ব্যক্তিগত ইমেল রিলে পরিষেবা কনফিগার করেন, অ্যাপল ব্যবহারকারীর আসল ইমেল ঠিকানায় বেনামী ঠিকানায় পাঠানো ইমেলগুলি ফরওয়ার্ড করে।

    অ্যাপল কেবলমাত্র ব্যবহারকারী তথ্য যেমন অ্যাপ্লিকেশনগুলির সাথে প্রথমবারের মতো কোনও ব্যবহারকারী সাইন ইন করে শেয়ার করে usic সাধারণত, ফায়ারবেস প্রথমবারের মতো কোনও ব্যবহারকারী অ্যাপলের সাথে সাইন ইন করে ডিসপ্লে নামটি সঞ্চয় করে, যা আপনি firebase.auth().currentUser.displayName তবে, আপনি যদি আগে ফায়ারবেস ব্যবহার না করে অ্যাপে কোনও ব্যবহারকারীকে সাইন ইন করতে অ্যাপল ব্যবহার করেন তবে অ্যাপল ব্যবহারকারীর প্রদর্শনের নাম ফায়ারবেস সরবরাহ করবে না।

পুনরায় অনুমোদন এবং অ্যাকাউন্ট লিঙ্কিং

একই প্যাটার্নটি reauthenticateWithPopup() এবং reauthenticateWithRedirect() এর সাথে ব্যবহার করা যেতে পারে, যা আপনি সংবেদনশীল ক্রিয়াকলাপগুলির জন্য একটি নতুন শংসাপত্র পুনরুদ্ধার করতে ব্যবহার করতে পারেন যা সাম্প্রতিক সাইন-ইন প্রয়োজন:

Web

import { getAuth, reauthenticateWithPopup, OAuthProvider } from "firebase/auth";

// Result from Redirect auth flow.
const auth = getAuth();
const provider = new OAuthProvider('apple.com');

reauthenticateWithPopup(auth.currentUser, provider)
  .then((result) => {
    // User is re-authenticated with fresh tokens minted and can perform
    // sensitive operations like account deletion, or updating their email
    // address or password.

    // The signed-in user info.
    const user = result.user;

    // You can also get the Apple OAuth Access and ID Tokens.
    const credential = OAuthProvider.credentialFromResult(result);
    const accessToken = credential.accessToken;
    const idToken = credential.idToken;

    // ...
  })
  .catch((error) => {
    // Handle Errors here.
    const errorCode = error.code;
    const errorMessage = error.message;
    // The email of the user's account used.
    const email = error.customData.email;
    // The credential that was used.
    const credential = OAuthProvider.credentialFromError(error);

    // ...
  });

Web

const provider = new firebase.auth.OAuthProvider('apple.com');

firebase
  .auth()
  .currentUser
  .reauthenticateWithPopup(provider)
  .then((result) => {
    // User is re-authenticated with fresh tokens minted and can perform
    // sensitive operations like account deletion, or updating their email
    // address or password.
    /** @type {firebase.auth.OAuthCredential} */
    var credential = result.credential;

    // The signed-in user info.
    var user = result.user;
     // You can also get the Apple OAuth Access and ID Tokens.
    var accessToken = credential.accessToken;
    var idToken = credential.idToken;

    // IdP data available in result.additionalUserInfo.profile.
      // ...
  })
  .catch((error) => {
    // Handle Errors here.
    var errorCode = error.code;
    var errorMessage = error.message;
    // The email of the user's account used.
    var email = error.email;
    // The firebase.auth.AuthCredential type that was used.
    var credential = error.credential;

    // ...
  });

এবং, আপনি বিভিন্ন পরিচয় সরবরাহকারীদের বিদ্যমান অ্যাকাউন্টগুলির সাথে লিঙ্ক করতে linkWithPopup() এবং linkWithRedirect() ব্যবহার করতে পারেন।

নোট করুন যে অ্যাপল আপনাকে তাদের অ্যাপল অ্যাকাউন্টগুলি অন্য ডেটার সাথে লিঙ্ক করার আগে ব্যবহারকারীদের কাছ থেকে সুস্পষ্ট সম্মতি পাওয়ার প্রয়োজন।

উদাহরণস্বরূপ, বর্তমান ফায়ারবেস অ্যাকাউন্টের সাথে একটি ফেসবুক অ্যাকাউন্ট লিঙ্ক করতে, ব্যবহারকারীকে ফেসবুকে স্বাক্ষর করে আপনি যে অ্যাক্সেস টোকেন পেয়েছেন তা ব্যবহার করুন:

Web

import { getAuth, linkWithPopup, FacebookAuthProvider } from "firebase/auth";

const auth = getAuth();
const provider = new FacebookAuthProvider();
provider.addScope('user_birthday');

// Assuming the current user is an Apple user linking a Facebook provider.
linkWithPopup(auth.currentUser, provider)
    .then((result) => {
      // Facebook credential is linked to the current Apple user.
      // ...

      // The user can now sign in to the same account
      // with either Apple or Facebook.
    })
    .catch((error) => {
      // Handle error.
    });

Web

const provider = new firebase.auth.FacebookAuthProvider();
provider.addScope('user_birthday');

// Assuming the current user is an Apple user linking a Facebook provider.
firebase.auth().currentUser.linkWithPopup(provider)
    .then((result) => {
      // Facebook credential is linked to the current Apple user.
      // Facebook additional data available in result.additionalUserInfo.profile,

      // Additional Facebook OAuth access token can also be retrieved.
      // result.credential.accessToken

      // The user can now sign in to the same account
      // with either Apple or Facebook.
    })
    .catch((error) => {
      // Handle error.
    });

ক্রোম এক্সটেনশনে ফায়ারবেস দিয়ে প্রমাণীকরণ করুন

আপনি যদি ক্রোম এক্সটেনশন অ্যাপ্লিকেশন তৈরি করছেন তবে অফস্ক্রিন নথি গাইড দেখুন।

নোট করুন যে আপনাকে অবশ্যই এখনও অ্যাপল সহ কাস্টম ডোমেনটি একইভাবে ডিফল্ট ফায়ারবাসএপ ডটকম ডোমেনের সাথে যাচাই করতে হবে:

http://auth.custom.example.com/.well-known/apple-developer-domain-association.txt

টোকেন প্রত্যাহার

অ্যাপলের প্রয়োজন যে অ্যাপ্লিকেশনগুলি যা অ্যাকাউন্ট তৈরি সমর্থন করে তাদের অবশ্যই অ্যাপ স্টোর পর্যালোচনা নির্দেশিকাগুলিতে বর্ণিত হিসাবে ব্যবহারকারীদের তাদের অ্যাকাউন্ট মুছে ফেলা শুরু করতে দেয়

এই প্রয়োজনীয়তা পূরণের জন্য, নিম্নলিখিত পদক্ষেপগুলি প্রয়োগ করুন:

  1. অ্যাপল বিভাগের সাথে কনফিগার সাইন ইন হিসাবে বর্ণিত হিসাবে অ্যাপল সরবরাহকারী কনফিগারেশনের সাথে সাইন ইন এর আইডি এবং ওআউথ কোড ফ্লো কনফিগারেশন বিভাগটি আপনি পূরণ করেছেন তা নিশ্চিত করুন।

  2. যেহেতু ফায়ারবেস যখন অ্যাপলের সাথে সাইন ইন দিয়ে তৈরি করা হয় তখন ব্যবহারকারী টোকেনগুলি সঞ্চয় করে না, তাই আপনাকে অবশ্যই ব্যবহারকারীকে তাদের টোকেনটি প্রত্যাহার করার আগে এবং অ্যাকাউন্টটি মুছে ফেলার আগে আবার সাইন ইন করতে বলবে।

    তারপরে, OAuthCredential থেকে অ্যাপল ওআউথ অ্যাক্সেস টোকেনটি পান এবং অ্যাপল ওআউথ অ্যাক্সেস টোকেনটি প্রত্যাহার করতে এটি revokeAccessToken(auth, token) কল করতে ব্যবহার করুন।

    const provider = new OAuthProvider('apple.com');
    provider.addScope('email');
    provider.addScope('name');
    
    const auth = getAuth();
    signInWithPopup(auth, provider).then(result => {
      // Get the Apple OAuth access token.
      const credential = OAuthProvider.credentialFromResult(result);
      const accessToken = credential.accessToken;
    
      // Revoke the Apple OAuth access token.
      revokeAccessToken(auth, accessToken)
        .then(() => {
          // Token revoked.
    
          // Delete the user account.
          // ...
        })
        .catch(error => {
          // An error happened.
          // ...
        });
    });
    
  3. অবশেষে, ব্যবহারকারী অ্যাকাউন্টটি মুছুন (এবং সমস্ত সম্পর্কিত ডেটা)।

উন্নত: নোড.জেএসে ফায়ারবেস দিয়ে প্রমাণীকরণ করুন

একটি নোড.জেএস অ্যাপ্লিকেশনটিতে ফায়ারবেস দিয়ে প্রমাণীকরণ করতে:

  1. তাদের অ্যাপল অ্যাকাউন্ট দিয়ে ব্যবহারকারীকে সাইন ইন করুন এবং ব্যবহারকারীর অ্যাপল আইডি টোকেন পান। আপনি এটি বিভিন্ন উপায়ে সম্পন্ন করতে পারেন। উদাহরণস্বরূপ, যদি আপনার নোড.জেএস অ্যাপ্লিকেশনটিতে একটি ব্রাউজারের সামনের প্রান্ত থাকে:

    1. আপনার ব্যাকএন্ডে, একটি এলোমেলো স্ট্রিং (একটি "ননস") উত্পন্ন করুন এবং এর SHA256 হ্যাশ গণনা করুন। ননস হ'ল আপনার ব্যাকএন্ড এবং অ্যাপলের অ্যাথ সার্ভারগুলির মধ্যে একক রাউন্ড ট্রিপকে বৈধতা দেওয়ার জন্য আপনি ব্যবহার করেন এমন এক সময়ের ব্যবহারের মান।

      Web

      const crypto = require("crypto");
      const string_decoder = require("string_decoder");
      
      // Generate a new random string for each sign-in
      const generateNonce = (length) => {
        const decoder = new string_decoder.StringDecoder("ascii");
        const buf = Buffer.alloc(length);
        let nonce = "";
        while (nonce.length < length) {
          crypto.randomFillSync(buf);
          nonce = decoder.write(buf);
        }
        return nonce.slice(0, length);
      };
      
      const unhashedNonce = generateNonce(10);
      
      // SHA256-hashed nonce in hex
      const hashedNonceHex = crypto.createHash('sha256')
        .update(unhashedNonce).digest().toString('hex');

      Web

      const crypto = require("crypto");
      const string_decoder = require("string_decoder");
      
      // Generate a new random string for each sign-in
      const generateNonce = function(length) {
        const decoder = new string_decoder.StringDecoder("ascii");
        const buf = Buffer.alloc(length);
        var nonce = "";
        while (nonce.length < length) {
          crypto.randomFillSync(buf);
          nonce = decoder.write(buf);
        }
        return nonce.slice(0, length);
      };
      
      const unhashedNonce = generateNonce(10);
      
      // SHA256-hashed nonce in hex
      const hashedNonceHex = crypto.createHash('sha256')
        .update(unhashedNonce).digest().toString('hex');
    2. আপনার সাইন-ইন পৃষ্ঠায়, অ্যাপল কনফিগারেশন সহ আপনার সাইন ইনটিতে হ্যাশ ননস নির্দিষ্ট করুন:

      <script src="https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js"></script>
      <div id="appleid-signin" data-color="black" data-border="true" data-type="sign in"></div>
      <script>
          AppleID.auth.init({
              clientId: YOUR_APPLE_CLIENT_ID,
              scope: 'name email',
              redirectURI: URL_TO_YOUR_REDIRECT_HANDLER,  // See the next step.
              state: '[STATE]',  // Optional value that Apple will send back to you
                                 // so you can return users to the same context after
                                 // they sign in.
              nonce: HASHED_NONCE  // The hashed nonce you generated in the previous step.
          });
      </script>
      
    3. পোস্ট এথ রেসপন্স সার্ভার-সাইড থেকে অ্যাপল আইডি টোকেন পান:

      app.post('/redirect', (req, res) => {
        const savedState = req.cookies.__session;
        const code = req.body.code;
        const state = req.body.state;
        const appleIdToken = req.body.id_token;
        if (savedState !== state || !code) {
          res.status(403).send('403: Permission denied');
        } else {
          // Sign in with Firebase using appleIdToken. (See next step).
        }
      });
      

    অ্যাপলের সাথে সাইন ইন করার জন্য আপনার ওয়েবপৃষ্ঠাটি কনফিগার করাও দেখুন।

  2. আপনি ব্যবহারকারীর অ্যাপল আইডি টোকেন পাওয়ার পরে, এটি একটি শংসাপত্রের অবজেক্ট তৈরি করতে ব্যবহার করুন এবং তারপরে শংসাপত্রের সাথে ব্যবহারকারীকে সাইন ইন করুন:

    Web

    import { getAuth, signInWithCredential, OAuthProvider } from "firebase/auth";
    
    const auth = getAuth();
    
    // Build Firebase credential with the Apple ID token.
    const provider = new OAuthProvider('apple.com');
    const authCredential = provider.credential({
      idToken: appleIdToken,
      rawNonce: unhashedNonce,
    });
    
    // Sign in with credential form the Apple user.
    signInWithCredential(auth, authCredential)
      .then((result) => {
        // User signed in.
      })
      .catch((error) => {
        // An error occurred. If error.code == 'auth/missing-or-invalid-nonce',
        // make sure you're sending the SHA256-hashed nonce as a hex string
        // with your request to Apple.
        console.log(error);
      });

    Web

    // Build Firebase credential with the Apple ID token.
    const provider = new firebase.auth.OAuthProvider('apple.com');
    const authCredential = provider.credential({
      idToken: appleIdToken,
      rawNonce: unhashedNonce,
    });
    
    // Sign in with credential form the Apple user.
    firebase.auth().signInWithCredential(authCredential)
      .then((result) => {
        // User signed in.
      })
      .catch((error) => {
        // An error occurred. If error.code == 'auth/missing-or-invalid-nonce',
        // make sure you're sending the SHA256-hashed nonce as a hex string
        // with your request to Apple.
        console.log(error);
      });

পরবর্তী পদক্ষেপ

কোনও ব্যবহারকারী প্রথমবারের মতো সাইন ইন করার পরে, একটি নতুন ব্যবহারকারী অ্যাকাউন্ট তৈরি করা হয় এবং শংসাপত্রগুলির সাথে লিঙ্ক করা হয় - অর্থাৎ, ব্যবহারকারীর নাম এবং পাসওয়ার্ড, ফোন নম্বর, বা লেখক সরবরাহকারীর তথ্য - ব্যবহারকারী সাইন ইন করেছেন। এই নতুন অ্যাকাউন্টটি আপনার ফায়ারবেস প্রকল্পের অংশ হিসাবে সঞ্চিত রয়েছে এবং ব্যবহারকারী কীভাবে সাইন ইন করেন তা নির্বিশেষে আপনার প্রকল্পের প্রতিটি অ্যাপ্লিকেশন জুড়ে কোনও ব্যবহারকারীকে সনাক্ত করতে ব্যবহার করা যেতে পারে।

  • In your apps, the recommended way to know the auth status of your user is to set an observer on the Auth object. তারপরে আপনি User অবজেক্ট থেকে ব্যবহারকারীর বেসিক প্রোফাইল তথ্য পেতে পারেন। ব্যবহারকারীদের পরিচালনা দেখুন।

  • আপনার Firebase Realtime Database এবং Cloud Storage সুরক্ষা বিধিগুলিতে , আপনি স্বাক্ষরিত ব্যবহারকারীর অনন্য ব্যবহারকারী আইডিটি auth ভেরিয়েবল থেকে পেতে পারেন এবং ব্যবহারকারী কোন ডেটা অ্যাক্সেস করতে পারে তা নিয়ন্ত্রণ করতে এটি ব্যবহার করতে পারেন।

আপনি ব্যবহারকারীদের বিদ্যমান ব্যবহারকারী অ্যাকাউন্টের সাথে লেখক সরবরাহকারী শংসাপত্রগুলি সংযুক্ত করে একাধিক প্রমাণীকরণ সরবরাহকারী ব্যবহার করে আপনার অ্যাপ্লিকেশনটিতে সাইন ইন করার অনুমতি দিতে পারেন।

কোনও ব্যবহারকারীকে সাইন আউট করতে, signOut কল করুন:

Web

import { getAuth, signOut } from "firebase/auth";

const auth = getAuth();
signOut(auth).then(() => {
  // Sign-out successful.
}).catch((error) => {
  // An error happened.
});

Web

firebase.auth().signOut().then(() => {
  // Sign-out successful.
}).catch((error) => {
  // An error happened.
});