Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

When and where is actionUpdate() used? #1

Open
steffes opened this issue Apr 10, 2020 · 4 comments
Open

When and where is actionUpdate() used? #1

steffes opened this issue Apr 10, 2020 · 4 comments
Labels
question Further information is requested

Comments

@steffes
Copy link

steffes commented Apr 10, 2020

I am building an iOS client using the RESTful API module and Firebase module. When is the actionUpdate() used? How do I invoke the saving of a new user in the fcmpush_user table?

if ($fcmUser === null) {
$fcmUser = new FcmUser();
$fcmUser->user_id = Yii::$app->user->id;
$fcmUser->token = $token;
}
return $this->asJson(['success' => ($fcmUser->save())]);

I have added all the credentials in the Firebase module. After checking the Mobile options, I am still not added to the fcmpush_user table
2020-04-10 11_59_22-(2) My Account - UW Orthopedics Faculty Enhancement

How can I add the fcm token, created on my iOS device, to the fcmpush_user table? Is this available through the RESTful API module? If not how can I refactor to make this possible?

@steffes
Copy link
Author

steffes commented Apr 17, 2020

@luke- how can I access the POST endpoint of fcm-push/token/update without being on a web browser on android? What needs to be in the header? is

data: { token: currentToken },
the only thing that needs to be in body?

@luke-
Copy link
Contributor

luke- commented Apr 18, 2020

@steffes if you plan to use the action outside of the browser context, you may also need to disable the CSRF protection (additional random param)

https://github.com/humhub/humhub-modules-fcm-push/blob/955db9730f07e51ddeda0b5a7d6dbe2631b009ae/controllers/TokenController.php

class TokenController extends Controller
{
    public $enableCsrfValidation = false;
    
    public function actionUpdate() {
        //...

Otherwise you’ll get a 403 error.

Otherwise it is a simple POST request with a single parameter named "token". So no JSON body or something like that is used. The current user is read from the session.

Do we need to change something?

@luke- luke- added the question Further information is requested label Apr 18, 2020
@steffes
Copy link
Author

steffes commented Apr 20, 2020

Applying the latest commit about CSP from @buddh4 to my /protected/humhub/config/web.php fixed my issue of the browser successfully updating the token. Adding

public $enableCsrfValidation = false;

to my TokenController helped from getting 404 as a POST response, to a 401 with {"success": false} response.

If I am outside of the browser context is there anyway to use the auth_token I get with the RESTful API Module (/api/v1/auth/login) to use in place of the browser session to get the current user so it can save the fcm token?

@luke-
Copy link
Contributor

luke- commented Apr 21, 2020

Unfortunately there is currently no link between the rest of the module and the FCM Push module yet.

You can either add FCM Push (add/update token) stuff to the existing Rest Module or add some basic auth to the FCM module (preferred).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants