অনুমোদন টোকেন পান
সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
একটি টোকেন কি?
ফ্লিট ইঞ্জিনের জন্য JSON ওয়েব টোকেন ব্যবহার করতে হবে (JWTs) স্বল্প-বিশ্বাসের পরিবেশ থেকে API পদ্ধতি কলের জন্য: স্মার্টফোন এবং ব্রাউজার।
একটি JWT আপনার সার্ভারে উদ্ভূত হয়, স্বাক্ষরিত হয়, এনক্রিপ্ট করা হয় এবং পরবর্তী সার্ভার ইন্টারঅ্যাকশনের জন্য ক্লায়েন্টের কাছে পাঠানো হয় যতক্ষণ না এটি মেয়াদ শেষ হয় বা আর বৈধ না হয়।
মূল বিবরণ
JSON ওয়েব টোকেন সম্পর্কে আরও তথ্যের জন্য, Fleet Engine Essentials- এ JSON ওয়েব টোকেন দেখুন।
কিভাবে ক্লায়েন্ট টোকেন পেতে?
একবার একজন ড্রাইভার বা ভোক্তা উপযুক্ত অনুমোদনের শংসাপত্র ব্যবহার করে আপনার অ্যাপে লগ ইন করলে, সেই ডিভাইস থেকে জারি করা যেকোনো আপডেটের জন্য অবশ্যই উপযুক্ত অনুমোদনের টোকেন ব্যবহার করতে হবে, যা ফ্লিট ইঞ্জিনকে অ্যাপের অনুমতির সাথে যোগাযোগ করে।
বিকাশকারী হিসাবে, আপনার ক্লায়েন্ট বাস্তবায়ন নিম্নলিখিতগুলি করার ক্ষমতা প্রদান করবে:
- আপনার সার্ভার থেকে একটি JSON ওয়েব টোকেন আনুন।
- টোকেন রিফ্রেশ কমাতে মেয়াদ শেষ না হওয়া পর্যন্ত টোকেনটি পুনরায় ব্যবহার করুন।
- মেয়াদ শেষ হয়ে গেলে টোকেনটি রিফ্রেশ করুন।
AuthTokenFactory
ক্লাস লোকেশন আপডেটের সময় অনুমোদন টোকেন তৈরি করে। SDK-কে ফ্লিট ইঞ্জিনে পাঠানোর জন্য আপডেট তথ্য সহ টোকেন প্যাকেজ করতে হবে। নিশ্চিত করুন যে আপনার সার্ভার-সাইড বাস্তবায়ন SDK শুরু করার আগে টোকেন ইস্যু করতে পারে।
ফ্লিট ইঞ্জিন পরিষেবা দ্বারা প্রত্যাশিত টোকেনগুলির বিশদ বিবরণের জন্য, ফ্লিট ইঞ্জিনের জন্য JSON ওয়েব টোকেন ইস্যু দেখুন৷
অনুমোদন টোকেন আনার উদাহরণ
এখানে একটি AuthTokenFactory
এর একটি কঙ্কাল বাস্তবায়ন রয়েছে:
class JsonAuthTokenFactory implements AuthTokenFactory {
private String vehicleServiceToken; // initially null
private long expiryTimeMs = 0;
private String vehicleId;
// This method is called on a thread whose only responsibility is to send
// location updates. Blocking is OK, but just know that no location updates
// can occur until this method returns.
@Override
public String getToken(AuthTokenContext authTokenContext) {
String vehicleId = requireNonNull(context.getVehicleId());
if (System.currentTimeMillis() > expiryTimeMs || !vehicleId.equals(this.vehicleId)) {
// The token has expired, go get a new one.
fetchNewToken(vehicleId);
}
return vehicleServiceToken;
}
private void fetchNewToken(String vehicleId) {
String url = "https://yourauthserver.example/token/" + vehicleId;
try (Reader r = new InputStreamReader(new URL(url).openStream())) {
com.google.gson.JsonObject obj
= com.google.gson.JsonParser.parseReader(r).getAsJsonObject();
vehicleServiceToken = obj.get("VehicleServiceToken").getAsString();
expiryTimeMs = obj.get("TokenExpiryMs").getAsLong();
// The expiry time could be an hour from now, but just to try and avoid
// passing expired tokens, we subtract 10 minutes from that time.
expiryTimeMs -= 10 * 60 * 1000;
this.vehicleId = vehicleId;
} catch (IOException e) {
// It's OK to throw exceptions here. The StatusListener you passed to
// create the DriverContext class will be notified and passed along the failed
// update warning.
throw new RuntimeException("Could not get auth token", e);
}
}
}
অনুমোদন সার্ভার থেকে JSON ফর্ম্যাটে একটি টোকেন আনতে এই বিশেষ বাস্তবায়নটি অন্তর্নির্মিত Java HTTP ক্লায়েন্ট ব্যবহার করে। ক্লায়েন্ট পুনঃব্যবহারের জন্য টোকেন সংরক্ষণ করে এবং পুরানো টোকেন মেয়াদ শেষ হওয়ার 10 মিনিটের মধ্যে হলে টোকেনটি পুনরায় আনয়ন করে।
আপনার বাস্তবায়ন ভিন্নভাবে কাজ করতে পারে, যেমন টোকেন রিফ্রেশ করতে একটি ব্যাকগ্রাউন্ড থ্রেড ব্যবহার করা।
ফ্লিট ইঞ্জিনের জন্য উপলব্ধ ক্লায়েন্ট লাইব্রেরিগুলির জন্য, অন-ডিমান্ড ট্রিপ পরিষেবাগুলির জন্য ক্লায়েন্ট লাইব্রেরিগুলি দেখুন৷
এরপর কি
ড্রাইভার SDK শুরু করুন
অন্য কিছু উল্লেখ না করা থাকলে, এই পৃষ্ঠার কন্টেন্ট Creative Commons Attribution 4.0 License-এর অধীনে এবং কোডের নমুনাগুলি Apache 2.0 License-এর অধীনে লাইসেন্স প্রাপ্ত। আরও জানতে, Google Developers সাইট নীতি দেখুন। Java হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2025-09-04 UTC-তে শেষবার আপডেট করা হয়েছে।
[[["সহজে বোঝা যায়","easyToUnderstand","thumb-up"],["আমার সমস্যার সমাধান হয়েছে","solvedMyProblem","thumb-up"],["অন্যান্য","otherUp","thumb-up"]],[["এতে আমার প্রয়োজনীয় তথ্য নেই","missingTheInformationINeed","thumb-down"],["খুব জটিল / অনেক ধাপ","tooComplicatedTooManySteps","thumb-down"],["পুরনো","outOfDate","thumb-down"],["অনুবাদ সংক্রান্ত সমস্যা","translationIssue","thumb-down"],["নমুনা / কোড সংক্রান্ত সমস্যা","samplesCodeIssue","thumb-down"],["অন্যান্য","otherDown","thumb-down"]],["2025-09-04 UTC-তে শেষবার আপডেট করা হয়েছে।"],[[["\u003cp\u003eFleet Engine utilizes JSON Web Tokens (JWTs) for API method calls originating from low-trust environments like smartphones and browsers, requiring these tokens to be signed by an appropriate service account on your server.\u003c/p\u003e\n"],["\u003cp\u003eClients, after logging in, must employ authorization tokens for updates, which are fetched from your server, reused until expiration, and then refreshed to maintain communication with Fleet Engine.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eAuthTokenFactory\u003c/code\u003e class generates authorization tokens for location updates, which are then packaged with the update information by the SDK and sent to Fleet Engine, requiring a server-side implementation for token issuance.\u003c/p\u003e\n"],["\u003cp\u003eAn example \u003ccode\u003eAuthTokenFactory\u003c/code\u003e implementation demonstrates fetching tokens in JSON format from an authorization server, saving them for reuse, and refreshing them within 10 minutes of expiry to ensure continuous authorization.\u003c/p\u003e\n"]]],[],null,["What is a token?\n\nFleet Engine requires the use of **JSON Web Tokens** (JWTs) for API method calls\nfrom **low-trust environments**: smartphones and browsers.\n\nA JWT originates on your server, is signed, encrypted, and passed to the client\nfor subsequent server interactions until it expires or is no longer valid.\n\n**Key details**\n\n- Use [Application Default Credentials](https://google.aip.dev/auth/4110) to authenticate and authorize against Fleet Engine.\n- Use an appropriate service account to sign JWTs. See [Fleet Engine serviceaccount](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/service-accounts#fleet_engine_service_account_roles) roles in **Fleet Engine Basics**.\n\nFor more information about JSON Web Tokens, see [JSON Web Tokens](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/jwt) in\n**Fleet Engine Essentials**.\n\nHow do clients get tokens?\n\nOnce a driver or consumer logs in to your app using the appropriate\nauthorization credentials, any updates issued from that device must use\nappropriate authorization tokens, which communicates to Fleet Engine the\npermissions for the app.\n\nAs the developer, your client implementation should provide the ability to do\nthe following:\n\n- Fetch a JSON Web Token from your server.\n- Reuse the token until it expires to minimize token refreshes.\n- Refresh the token when it expires.\n\nThe `AuthTokenFactory` class generates authorization tokens at location update\ntime. The SDK must package the tokens with the update\ninformation to send to Fleet Engine. Make sure that your server-side\nimplementation can issue tokens before initializing the SDK.\n\nFor details of the tokens expected by the Fleet Engine service, see [Issue JSON\nWeb Tokens](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/issue-jwt) for Fleet Engine.\n\nExample of an authorization token fetcher\n\nHere is a skeleton implementation of an `AuthTokenFactory`: \n\n class JsonAuthTokenFactory implements AuthTokenFactory {\n private String vehicleServiceToken; // initially null\n private long expiryTimeMs = 0;\n private String vehicleId;\n\n // This method is called on a thread whose only responsibility is to send\n // location updates. Blocking is OK, but just know that no location updates\n // can occur until this method returns.\n @Override\n public String getToken(AuthTokenContext authTokenContext) {\n String vehicleId = requireNonNull(context.getVehicleId());\n\n if (System.currentTimeMillis() \u003e expiryTimeMs || !vehicleId.equals(this.vehicleId)) {\n // The token has expired, go get a new one.\n fetchNewToken(vehicleId);\n }\n\n return vehicleServiceToken;\n }\n\n private void fetchNewToken(String vehicleId) {\n String url = \"https://yourauthserver.example/token/\" + vehicleId;\n\n try (Reader r = new InputStreamReader(new URL(url).openStream())) {\n com.google.gson.JsonObject obj\n = com.google.gson.JsonParser.parseReader(r).getAsJsonObject();\n vehicleServiceToken = obj.get(\"VehicleServiceToken\").getAsString();\n expiryTimeMs = obj.get(\"TokenExpiryMs\").getAsLong();\n\n // The expiry time could be an hour from now, but just to try and avoid\n // passing expired tokens, we subtract 10 minutes from that time.\n expiryTimeMs -= 10 * 60 * 1000;\n this.vehicleId = vehicleId;\n } catch (IOException e) {\n // It's OK to throw exceptions here. The StatusListener you passed to\n // create the DriverContext class will be notified and passed along the failed\n // update warning.\n throw new RuntimeException(\"Could not get auth token\", e);\n }\n }\n }\n\nThis particular implementation uses the built-in Java HTTP client to fetch a\ntoken in JSON format from the authorization server. The client saves the token\nfor reuse and re-fetches the token if the old token is within 10 minutes of its\nexpiry time.\n\nYour implementation may do things differently, such as using a background thread\nto refresh tokens.\n\nFor the available client libraries for Fleet Engine, see\n[Client libraries for on-demand trips services](/maps/documentation/mobility/fleet-engine/essentials/client-libraries-trips).\n\nWhat's next\n\n[Initialize the Driver SDK](/maps/documentation/mobility/driver-sdk/on-demand/android/initialize-sdk)"]]