After we get the user access token using Sign in with slack, we can query identity information as shown below:
{
ok: true,
user: {
name: 'arbxxxxxxx',
id: 'U0XXXXXXX',
email: 'arbxxxxxxx#xxxxxxx.com'
},
team: { id: 'T0XXXXXXX' },
response_metadata: {
scopes: [ 'identity.basic', 'identity.email', 'openid' ],
acceptedScopes: [ 'identity.basic' ]
}
}
The current workspace is team: { id: 'T0XXXXXXX' }.
How can I get all the other workspaces?
FYI: Sign in and acces token usage is shown in at this gist: https://gist.github.com/seratch/92bf98679d7a37a87dfa7376d02a51a1
With the exception of Org Apps installed on a Grid, users actually auth per workspace, and each is a unique identity, there's no real concept of a single identity that spans across workspaces
Related
Since Google is deprecating Google contacts API and instead advising us to use Google People API to add/create/delete contacts. I was able to create, get Google contacts, Sample code is below:
const { google } = require("googleapis")
const path = require("path")
const keyFile = path.join(__dirname, "serviceAccCredentials.json")
const scopes = [
"https://www.googleapis.com/auth/contacts",
"https://www.googleapis.com/auth/contacts.readonly"
]
function log(arg) {
console.log(JSON.stringify(arg, null, 4))
}
const run = async () => {
try {
const { people, contactGroups } = google.people({
version: "v1",
auth: await google.auth.getClient({
keyFile,
scopes
})
})
const createContact = await people.createContact(
{
requestBody: {
names: [
{
givenName: "Yacov 3",
familyName: "110$"
}
],
"memberships": [
{
"contactGroupMembership": {
contactGroupId: 'myContacts'
// "contactGroupResourceName": "contactGroups/myContacts"
}
}
]
}
}
)
log(createContact.data)
const afterResponse = await people.connections.list({
resourceName: "people/me",
personFields: "names",
})
log(afterResponse.data)
} catch (e) {
console.log(e)
}
}
run()
Problem is that i don't see the contacts created with the service account under the Google contacts. Normally the service account is created for the G-suit user, under the G-suit domain wide delegation settings, i added the project id with scope as well. Also People API is enabled in the service account.
Further, In the playground area of Google's official documentation when i tried to create the a Google contact, it worked. The request from there API explorer / playground looks like this
const createContact = await people.createContact({
"personFields": "names",
"sources": [
"READ_SOURCE_TYPE_CONTACT"
],
"prettyPrint": true,
"alt": "json",
"resource": {
"names": [
{
"givenName": "test 2",
"familyName": "playground"
}
],
"memberships": [
{
"contactGroupMembership": {
"contactGroupResourceName": "contactGroups/myContacts"
}
}
]
}
})
Strangely, all these properties like contactGroupResourceName, personFields, sources, alt, prettyPrint doesn't exists.
can anyone really tell me what is going on.
PS: i can not and don't want to use OAuth2 since the application is going to be server to server communication, wouldn't involve any human consent. Thanks
Issue:
You might have enabled domain-wide delegation for your service account, but you are not using it to impersonate a regular user.
The purpose of domain-wide delegation is for the service account to act on behalf of any user in the domain, but in order to do that, you have to specify which user you want the service account to impersonate.
Otherwise, the service account will access its own resources (its Contacts, its Drive, its Calendar, etc.) not the resources of a regular account. Therefore, you'll not see the created contacts if you access Contacts UI with a regular account, since contacts were not created for this account.
Solution:
You need to impersonate the account for which you want to create contacts.
In order to do that, since you're using Node's getClient(), you should specify the email address of the account you want to impersonate, as shown here:
auth.subject = "email-address-to-impersonate";
Update:
In this case, you could do the following:
let auth = await google.auth.getClient({
keyFile,
scopes
});
auth.subject = "email-address-to-impersonate";
const { people, contactGroups } = google.people({
version: "v1",
auth: auth
})
Reference:
Google Auth Library: Node.js Client
I am building Graphql api with Strapi. It's a simple application which user can signup and save some of his/her information. I have two tables for that, User [Which is Strapi provided] and Profile which i use to store user additional information. The two tables has relationship
User [User has and belongs to one Profile]
Profile Profile has and belongs to one User and contact component structure.
I want to be able to fetch the current logged in user and it's information from Profile table, but the Contact field which i save as component type return null.
Here is what i am doing so far
extensions/user-permission/config/schema.graphql.js
module.exports = {
definition: `
extend type UsersPermissionsMe {
profile: ProfileMe
}
type ProfileMe {
id: ID!
website: String!
description: String!
contact: ContactMe
}
type ContactMe {
id: ID!
name: String!
phone: String!
email: String!
}
`
}
extensions/user-permission/services/User.js
'use strict';
module.exports = {
fetchAuthenticatedUser(id) {
return strapi.query('user', 'users-permissions').findOne({ id }, ['role', 'profile']);
},
};
And when run GraphQl Query
query {
me {
username
email
profile {
website
description
contact {
name
phone
email
}
}
}
}
it returned
{
"data": {
"me": {
"username": "company",
"email": "company#test.com",
"profile": {
"website": "http://localhost.com",
"description": "lorem text",
"contact": null
}
}
}
}
I want to also get contact data here. I hope someone on Internet can help me.
please help, thanks you.
I've scoured all four corners of interweb trying to find documentation on how to do this. But my journey has been unsuccessful so far. Part way through the search, I was able to find out how to mention a User (not a bot), and that was even a pain to find. I found that you have to post a field named msteams at the top level of the "any" object parameter which is an object consisting of an entities array. That array is an array of objects. The following use of adaptiveCard works when mentioning a user with the proper values replacing username and userID:
CardFactory.adaptiveCard({
$schema: 'http://adaptivecards.io/schemas/adaptive-card.json',
type: 'AdaptiveCard',
msteams: {
entites: [
{
type: 'mention',
text: '<at>(username)</at>',
mentioned: {
id: <userID>,
name: <username>,
role: 'user'
}
}
]
}
body: [
{
type: 'TextBlock',
text: '<at>(userName)</at>',
}
]
});
The documentation of CardFactory.adaptiveCard just lists the parameter as an any Object and gives a small example not displaying an exhaustive list of fields of this parameter. It also posts a link to the Adaptive Card documentation, but that's what it's abstracting and the fields are not 1:1 (point and case this msteams object that is never referenced in the Adaptive Card documentation from what I can tell). I want to mention the bot itself that is posting this Adaptive Card. I've attempted to replace the mentioned object with the following
{
"id": "a3216960-131c-11eb-xxxx-xxxxxxxxx",
"name": "Bot",
"role": "bot"
}
This is equivalent to the object that I'm using to mention the "from" user in the adaptive card. But this is the recipient. The from user which is successfully mentioned is formatted like the following:
{
"id": "c3370a7c-95f2-4a60-xxxx-xxxxxxxxx",
"name": "User",
"role": "user"
}
Any help/guidance, tips, references would be greatly appreciated!
Currently #mention a bot in Adaptive card is not supported. You can #mention user in Adaptive card.
My app currently uses Parse and it's time to migrate. I am either considering hosting my own Parse Server or use Firebase. I am looking for guidance on how to approach my data migration problem to Firebase based on my current data model.
I have a table Users and that table, aside from all the normal columns, has Partner column which is of type User.
The flow, works like this:
User 1 signs up
User 1 invites User 2
User 2 receives invite e-mail with invite code
User 2 goes to app and signs-up using that code
And then I have a Parse cloud function that joins both users as partners adding each other's IDs to the respective column.
The partners are connected via a GCM topic name, so I can push notifications just to these two people.
So this is what I would like to achieve in Firebase. I would like to have two users to connect together in a way.
Maybe I could have a json like this:
partners: {
topic_name_partner1: {
user1: {info about user1},
user2: {info about user2}
},
topic_name_partner2: {
user1: {info about user1},
user2: {info about user2}
},
topic_name_partner3: {
user1: {info about user1},
user2: {info about user2}
}
....etc
}
Would this approach make sense ? Obviously I want a scalable application, so looking for help as well to best represent the data in that sense.
And, lastly, does Firebase have Cloud Functions like Parse? If not, how can I connect both users when the second user is registering? Maybe I have to look up Ref for the topic_name_partner1 string and then when finding it, update user2 with the reference to that user?
Thanks!
Based on this firebase structure guide, here is what I will do
users: {
user1: {
name: "user1",
partner: "topic_name_partner1",
... other info
},
user2: {
name: "user2",
partner: "topic_name_partner1",
... other info
},
user3: {
name: "user3",
partner: "topic_name_partner2",
... other info
}
}
partners: {
topic_name_partner1: {
user1: true,
user2: true
},
topic_name_partner2: {
user3: true
}
}
so the data will not so big when I just want to get a list of users in a partner without their details.
and currently Firebase does not have Cloud Functions feature like Parse, so you have to move the data from the client (or probably use their Firebase SDK for server).
So I have set up a google service account for one of my apps. My intention is to keep a google calendar associated with the admin portal that all of the admins can post events to. I have got the JWT auth working I can post events to the calendar and perform other API actions. However, for some reason I cannot change the access control rules on the primary calendar. It is initialized with a single acl rule (role: owner, scope: {type: user, value: service_account_id}), and when I try to add public read access (role: reader, scope: {type: default}) like so:
POST https://www.googleapis.com/calendar/v3/calendars/primary/acl
Authorization: Bearer my_jwt_here
{
"role":"reader",
"scope":{
"type":"default"
}
}
I get the following error:
{
"error": {
"errors": [
{
"domain": "calendar",
"reason": "cannotRemoveLastCalendarOwnerFromAcl",
"message": "Cannot remove the last owner of a calendar from the access control list."
}
],
"code": 403,
"message": "Cannot remove the last owner of a calendar from the access control list."
}
}
This doesn't make any sense to me because this request shouldn't be trying to remove any access control rules. When I create a secondary calendar and do this I have no issues. When I do this with the primary calendar of my personal google account I have no issues. Is this some behavior specific to service accounts that I am not familiar with or what? I could settle for using a non-primary calendar but it bothers me that this isn't working. Any advice is appreciated.
so I found a weird work around for this issue and im posting here because I could not find SQUAT to help resolve this so hopefully this saves others some hassle.
I will also post some common problems I found when creating a organization-wide calendar (whether this is your use case or not I believe these tips will be helpful) - Jump to the bottom of the solution to this particular error.
First I needed to set up authentication with google calendar:
const { google } = require("googleapis");
const calendar = google.calendar("v3");
const scopes = [
"https://www.googleapis.com/auth/admin.directory.resource.calendar",
"https://www.googleapis.com/auth/calendar",
"https://www.googleapis.com/auth/admin.directory.user",
];
const path = require("path");
const key = require(path.join(__dirname, "google-cal-api.json"));
I created a service account and then allowed it domain wide delegation with the above listed scopes; then downloaded the key. Now if you want to do actions like create calendar events FOR users within this domain what you have to do is generate a JWT token that 'impersonates' the user whos calendar you wish to interact with; like so
const generateInpersonationKey = (email) => {
var jwtClient = new google.auth.JWT(
key.client_email,
null,
key.private_key,
scopes,
email
);
return jwtClient;
};
To set up a JWT client for the service account itself (and so you can create a calendar people can subscribe to; in our case it was a google calendar to show whos on leave within the workplace; so a calendar that has ALL that people can subscribe and toggle on/off was ideal) you just replace the email with 'null' and it defaults to itself, instead of 'impersonating' someone within the domain wide org.
Creating events are simple, follow the google cal api docs, depending on the auth token will depend on where the calendar is generated
JUMP HERE FOR THE IMMEDIATE SOLUTION TO THE ABOVE
For resolving the issue you pointed out; What I did was set my personal accounts email as an owner of this service accounts calendar with the following NodeJS code:
var request = await calendar.acl.insert({
auth,
calendarId: "primary",
resource: {
role: "owner",
scope: {
type: "user",
value: "callum#orgdomain.com",
},
},
});
I set myself as an owner, then I went to Google Calendar API > Patch (Try Me) filled in the calendarId as the service account with the calendar im trying to restrict; and then rule ID would be the gsuite domain domain:orgdomain.com The body should be
{
"role": "reader",
"scope": {
"type": "domain",
"value": "orgdomain.com"
}
}
And thats how I was able to restrict people within our gsuite domain from deleting or editing custom calendar events. This solution is coming from the perspective of someone who originally inserted the domain ACL as
var request = await calendar.acl.insert({
auth,
calendarId: "primary",
resource: {
role: "owner",
scope: { type: "domain", value: "orgdomain.com" },
},
});
Because adding it as a 'reader' like this messes with the service account ownership and wont allow anything but owner
Hope this has been helpful
Callum