Unable to invite teachers, students to Classroom via API - google-api

Having an issue with google classroom api
Using Google Classroom API v1, authorized with oAuth2, requesting
teachers.create({
courseId,
requestBody: {
userId: email
}
})
and getting the following error:
config: {
> url: 'https://classroom.googleapis.com/v1/courses/237584048292/teachers',
> method: 'POST',
> data: {
> courseId: '237584048292',
> profile: {},
> userId: 'dgrz5.0#gmail.com'
> },
> body: '{"courseId":"237584048292","profile":{},"userId":"dgrz5.0#gmail.com"}',
> },
> data: {
> error: {
> code: 403,
> message: 'The caller does not have permission',
> errors: [Array],
> status: 'PERMISSION_DENIED'
> }
> },
>
> status: 403,
> statusText: 'Forbidden',
> request: {
> responseURL: 'https://classroom.googleapis.com/v1/courses/237584048292/teachers'
> }
> }

Go to your storage section of your Database.Then in Rules ,allow read, write and remove the condition for authentication.

Related

Shopify Storefront GraphQL 403 Forbidden

I have a custom app I'm building and it has all of the access the app could need. I'm passing in the application storefront access token but am getting a 403 error of 'Forbidden'.
Here is my query:
const shopifyUserQuery = `mutation {
customerCreate(
input: {
firstName: ${values.firstName},
lastName: ${values.lastName},
email: ${values.email},
password: ${values.password}
}
) {
customer {
id,
firstName,
lastName,
email,
}
customerUserErrors {
field,
message,
}
customer {
id
}
}
}`
And then here is the fetch call:
const shopifyUser = await fetch(process.env.SHOPIFY_SF_API_URL, {
'body': shopifyUserQuery,
'method': 'post',
'headers': {
'X-Shopify-Access-Token': process.env.SHOPIFY_SF_API_ACCESS_TOKEN,
'Content-Type': 'application/graphql',
},
}).then((sres) => console.log(sres))
Any help is appreciated as I'm currently at a loss.

Unable to create a new conversation in a channel

I'm attempting to create a new thread in a Teams Channel a bot has been added to after a specific Dialog step. I have attempted to follow the following sample: https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/typescript_nodejs/58.teams-start-new-thread-in-channel, where I use sendMessageToTeamsChannel:
const activity = MessageFactory.text('test') as Activity;
const ref = await TeamsInfo.sendMessageToTeamsChannel(turnContext, activity, teamsChannelId, process.env.MICROSOFT_APP_ID);
.
I have also attempted creating a new client with Microsoft App credentials and passing conversation params:
const credentials = new MicrosoftAppCredentials(process.env.MICROSOFT_APP_ID!, process.env.MICROSOFT_APP_PASSWORD!);
const client = new ConnectorClient(credentials, { baseUri: serviceUrl });
;
const conversationParams = {
bot: channelAccount,
channelData: {
channel: {
id: teamsChannelId,
tenant: tenantId
}
},
isGroup: true,
activity: message
} as ConversationParameters;
const ref = await client.conversations.createConversation(conversationParams);
Both fail with a 404 error code:
DialogContextError: Conversation not found.
{
code: 'ConversationNotFound',
statusCode: 404,
request: WebResource {
streamResponseBody: false,
url: 'https://smba.trafficmanager.net/amer/v3/conversations',
method: 'POST',
headers: [HttpHeaders],
body: BODY_HERE,
query: undefined,
formData: undefined,
withCredentials: false,
abortSignal: undefined,
timeout: 0,
onUploadProgress: undefined,
onDownloadProgress: undefined,
proxySettings: undefined,
keepAlive: undefined,
agentSettings: undefined,
operationSpec: [Object]
},
response: {
body: '{"error":{"code":"ConversationNotFound","message":"Conversation not found."}}',
headers: [HttpHeaders],
status: 404
},
body: { error: [Object] }
},
dialogContext: {
activeDialog: 'WATERFALL_DIALOG',
parent: 'sampleDialog',
stack: [ [Object] ]
}
}
. Is it not possible to start a new conversation/thread in a channel from a 1-on-1 conversation even if the bot is added to the channel and I have the channelId?
Additional information: I've built this bot using the YoTeams Bot scaffold and it is a Dialog based Bot so I have not exactly copied the sample.

I can't access $auth.user from auth plugin or middleware using nuxtjs and getting api from laravel

My goal is that i want to access $auth.user.roles from plugin and middleware to be able to not let this role reach the other role page.
what is expected is that when console.log($auth.user) it gives me the user data (id,...) and when a console.log($auth.loggedIn)it gives me true.
My problem is that i can't access $auth.user from plugin and middleware to chieve that which $auth.user = null and $auth.loggedIn = false while im logged in.
here is my nuxt.config.js:
axios: {
baseURL: env.parsed.API_URL || 'http://localhost:3000/api',
debug:true},
auth: {
strategies: {
local: {
endpoints: {
login: {
url: '/auth/signin',
method: 'post',
propertyName: 'data.token'
},
user: {
url: '/auth/me',
method: 'get',
propertyName: 'data'
},
logout: {
url: '/auth/signout',
method: 'post'
},
tokenRequired: true,
tokenType: 'bearer',
globalToken: true,
autoFetchUser: true
},
},
},
redirect:false,
plugins: [ '~/plugins/roles.js' ]
},
here is my plugins/roles.js :
export default function ({app}) {
const username = app.$auth.user
if (!app.$auth.loggedIn) {
return console.log(username ,'roles plugin ', app.$auth.loggedIn)
}}
here is the res: null roles plugin false
the same result using this code:
export default function ({$auth}) {
const username = $auth.user
if (!app.$auth.loggedIn) {
return console.log(username ,'roles plugin', $auth.loggedIn)
}}
Ps:when i use $auth.user in my vue pages it gives me the whole user data (thats wonderfull)
I searched about this problem so i found common answers like :
*Change the user propertyName to false.
*reinstall node_modules.
but same result
Thank you every one <3

Unable to use Google Play Developer API even after server to server authentication

I am trying to call Purchases.Subscriptions: get from my local server, but I am getting an error message saying Error: Login Required.
I have already created a service account with a role of Project Owner as described here. I then set the GOOGLE_APPLICATION_CREDENTIALS environment variable and made it point to the JSON file that was downloaded as mentioned here.
Lastly, I tried running some example code that was meant for server-to-server authentication based off the website docs example to see if I could authenticate successfully:
import { google } from 'googleapis'
async function main() {
try {
const auth = new google.auth.GoogleAuth({
scopes: ['https://www.googleapis.com/auth/androidpublisher']
})
const authClient = await auth.getClient()
const project = await auth.getProjectId()
const publisher = google.androidpublisher('v3')
const result = await publisher.purchases.subscriptions.get({
packageName: 'com.mywebsite.subdomain',
subscriptionId: 'com.mywebsite.subscription_name',
token: '...my purchase token...'
})
console.log(result)
} catch (error) {
console.error(error)
}
}
main()
I just used the Billing API instead of the Compute API, otherwise my example is the same as the one given in the docs. I am not sure why I am having issues, any help would be appreciated!
Full error:
{ Error: Login Required
at Gaxios.request (/Users/squadri/Desktop/googlenode/node_modules/gaxios/src/gaxios.ts:86:15)
at process._tickCallback (internal/process/next_tick.js:68:7)
response:
{ config:
{ url:
'https://www.googleapis.com/androidpublisher/v3/applications/com.mywebsite.subdomain/purchases/subscriptions/com.mywebsite.subscription_name/tokens/...my%20purchase%20token...',
method: 'GET',
paramsSerializer: [Function],
headers: [Object],
params: [Object: null prototype] {},
validateStatus: [Function],
retry: true,
responseType: 'json',
retryConfig: [Object] },
data: { error: [Object] },
headers:
{ 'alt-svc': 'quic=":443"; ma=2592000; v="46,43,39"',
'cache-control': 'private, max-age=0',
connection: 'close',
'content-encoding': 'gzip',
'content-type': 'application/json; charset=UTF-8',
date: 'Tue, 20 Aug 2019 04:41:29 GMT',
expires: 'Tue, 20 Aug 2019 04:41:29 GMT',
server: 'GSE',
'transfer-encoding': 'chunked',
vary: 'Origin, X-Origin',
'www-authenticate': 'Bearer realm="https://accounts.google.com/"',
'x-content-type-options': 'nosniff',
'x-frame-options': 'SAMEORIGIN',
'x-xss-protection': '1; mode=block' },
status: 401,
statusText: 'Unauthorized' },
config:
{ url:
'https://www.googleapis.com/androidpublisher/v3/applications/com.mywebsite.subdomain/purchases/subscriptions/com.mywebsite.subscription_name/tokens/...my%20purchase%20token...',
method: 'GET',
paramsSerializer: [Function],
headers:
{ 'x-goog-api-client': 'gdcl/3.1.0 gl-node/10.16.1 auth/5.2.0',
'Accept-Encoding': 'gzip',
'User-Agent': 'google-api-nodejs-client/3.1.0 (gzip)',
Accept: 'application/json' },
params: [Object: null prototype] {},
validateStatus: [Function],
retry: true,
responseType: 'json',
retryConfig:
{ currentRetryAttempt: 0,
retry: 3,
retryDelay: 100,
httpMethodsToRetry: [Array],
noResponseRetries: 2,
statusCodesToRetry: [Array] } },
code: 401,
errors:
[ { domain: 'global',
reason: 'required',
message: 'Login Required',
locationType: 'header',
location: 'Authorization' } ] }
Try this code snippet for example.
Print apks list of specific packageName using googleapi, androidpublisher and service account authentication (v3).
const {google} = require('googleapis');
const key = require('./privateKey.json')
const packageName = "com.company.example"
let client = new google.auth.JWT(
key.client_email,
undefined,
key.private_key,
['https://www.googleapis.com/auth/androidpublisher']
)
const androidApi = google.androidpublisher({
version: 'v3',
auth: client
})
async function getApksList() {
let authorize = await client.authorize();
//insert edit
console.log('authorize :', authorize);
let res = await androidApi.edits.insert({
packageName: packageName
})
//get edit id
let editId = res.data.id
const res = await androidApi.edits.apks.list({
editId: editId,
packageName: packageName
});
console.log(`Result ${(JSON.stringify(res))}`);
}
getApksList().catch(console.error);
You need to add your JSON key file to google.auth.GoogleAuth:
const auth = new google.auth.GoogleAuth({
keyFile: process.env.GOOGLE_APPLICATION_CREDENTIALS,
scopes: ['https://www.googleapis.com/auth/androidpublisher']
});
See: https://github.com/googleapis/google-api-nodejs-client/blob/master/samples/jwt.js
You need to pass the auth field (authClient) to google.androidpublisher
const publisher = google.androidpublisher({
version: 'v3',
auth: authClient
})

SailsJS Session not stored in local MemoryStore

I am building a react (ES6) application with Webpack in SailsJS.
The problem I came across is that session is not properly handled or stored in Local Memory Store IF the action is triggered from the frontend
Setup:
// TestAPIController:
module.exports = {
create: function(req, res){
// TODO: Add user authentication piece
var user = {name: 'test user'};
req.session.user = user.name;
req.session.authenticated = true;
console.log('session:', req.session);
// req.session.save();
res.json(req.session);
},
echo: function(req, res){
console.log('session:', req.session);
return res.json({message:'got it'});
}
};
Policy:
TestAPIController: {
echo : 'sessionAuth'
}
Route:
'GET /TestAPI/create' : {
controller: 'TestAPIController',
action:'create'
},
'GET /TestAPI/echo' : {
controller: 'TestAPIController',
action:'echo'
},
Front End
onClickCreate(e){
fetch('/TestAPI/create').then( res => res.json());
}
onClickEcho(e){
fetch('/TestAPI/echo').then(res => res.json());
}
MarkUp
<li><a onClick={_this.onClickCreate}>Create Test</a></li>
<li><a onClick={_this.onClickEcho}>Echo Test</a></li>
Senario A
Click on Create Console Log: [CORRECT!]
Requested :: GET /TestAPI/create
session: Session {
cookie:
{ path: '/',
_expires: 2017-01-18T20:21:01.069Z,
originalMaxAge: 86400000,
httpOnly: true },
user: 'test user',
authenticated: true }
And Then click on Echo, Console Log: [WRONG!]
Requested :: GET /TestAPI/echo
verbose: Sending 403 ("Forbidden") response:
You are not permitted to perform this action.
Senario B
Now go to http://localhost:3000/TestAPI/create in the chrome browser's URL
Browser prints the return from the call. and Log:
Requested :: GET /TestAPI/create
session: Session {
cookie:
{ path: '/',
_expires: 2017-01-18T20:21:13.645Z,
originalMaxAge: 86400000,
httpOnly: true },
user: 'test user',
authenticated: true }
And then enter http://localhost:3000/TestAPI/echo in url address
Browser prints the return from the call [CORRECT!]
Requested :: GET /TestAPI/echo
session: Session {
cookie:
{ path: '/',
_expires: 2017-01-18T20:25:24.019Z,
originalMaxAge: 86400000,
httpOnly: true },
user: 'test user',
authenticated: true }
Maybe there is some fundamental principle I'm not following?
Or maybe there is a better way to control sessions?
Any help would be appreciated.
You have the solution here guys: https://github.com/balderdashy/sails/issues/3965

Resources