Reputation: 423
when I'm using the node js, to create enterprises in Android management API
I have created all credentials in my google console
To create an Android Management API service account with authentication in the Google Cloud Console, follow these step-by-step instructions:
Step 1: Set up a project in the Google Cloud Console
Go to the Google Cloud Console (console.cloud.google.com).
Create a new project or select an existing project from the project dropdown menu.
Step 2: Enable the Android Management API
In the Cloud Console, navigate to the API Library.
Search for "Android Management API" and select it.
Click the "Enable" button to enable the API.
Step 3: Create a service account
In the Cloud Console, navigate to the IAM & Admin section.
Select "Service Accounts" from the left-hand menu.
Click on the "Create Service Account" button.
Provide a name and optional description for the service account.
Click on the "Create" button.
Step 4: Grant necessary permissions to the service account
After creating the service account, you will be redirected to the "IAM & Admin" page.
Locate the newly created service account in the list and click on the pencil icon to edit it.
In the "Permissions" tab, click on the "Add Another Role" button.
Search for "Android Management API Administrator" and select it.
Click the "Save" button to grant the necessary permissions.
Step 5: Generate a private key for the service account
In the "IAM & Admin" page, locate the service account you created and click on the vertical ellipsis (⋮) button.
Select "Create Key" and choose the JSON key type.
Click on the "Create" button to download the private key JSON file.
then I start to create an enterprise programmatically referred to the documentation guide link here
as per the documentation,
* Displays the signup URL to the admin and returns the enterprise token which
* is generated after the admin goes through the signup flow. This functionality
* must be implemented by your management console.
but I could not get the enterprise token from the signup Url responseURL: 'https://androidmanagement.googleapis.com/v1/signupUrls?projectId=ProjectId&callbackUrl=callbackURL'
https://play.google.com/work/adminsignup?token=2e82428rffjgdcsaucssfhjz
here is I've tried:
app.get('/callback', async (req, res) => {
const { code } = req.query;
try {
const { tokens } = await oauth2Client.getToken(code)
const accessToken = tokens.access_token;
const refreshToken = tokens.refresh_token;
console.log("Access Token:", accessToken);
//console.log("Refresh Token:", refreshToken);
const tokenEndpoint = 'https://accounts.google.com/o/oauth2/v2/auth';
oauth2Client.setCredentials({
clientId: Authdata.web.client_id,
clientSecret: Authdata.web.client_secret,
access_token: accessToken,
refresh_token: refreshToken,
});
getEnterprisetoken()
// You can use the access token and refresh token to make API requests
res.send('Authorization successful!');
} catch (error) {
console.error('Error retrieving access token:', error);
res.status(500).send('Error retrieving access token');
}
});
function getEnterprisetoken(){
const signupUrl = await androidManagementClient.signupUrls.create({
projectId: projectId,
callbackUrl: callbackUrl,
});
console.log(signupUrl)
console.log(signupUrl)
const enterpriseToken = await displayUrlToAdmin(signupUrl.data.url);
const enterprise = await androidManagementClient.enterprises.create({
projectId: projectId,
signupUrlName: signupUrl.data.name,
**enterpriseToken: enterpriseToken,**
headers: {
Authorization: `Bearer ${accessToken}`,
},
}
when I try this, that having invalid enterprise token error also I've tried to the access token and refresh token they are all having invalid how do I get the enterprise token and create the enterprise?
Upvotes: 0
Views: 150