https://github.com/remotesynth/kinvey-login-sample
A simple example showing anonymous, social and kinvey user authentication
https://github.com/remotesynth/kinvey-login-sample
Last synced: about 1 year ago
JSON representation
A simple example showing anonymous, social and kinvey user authentication
- Host: GitHub
- URL: https://github.com/remotesynth/kinvey-login-sample
- Owner: remotesynth
- Created: 2018-01-16T20:52:14.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-12T15:11:17.000Z (over 8 years ago)
- Last Synced: 2025-02-13T23:18:15.622Z (over 1 year ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Login Sample Application built with Kinvey
This is a simple example demonstrating how to implement the following in [Kinvey](https://www.kinvey.com/):
* Creating an implicit (anonymous) active user
* Signing up and logging in with Kinvey authentication
* Signing up and logging in with Google authentication
* Restricting data access via roles
The code relies upon two custom endpoints in Kinvey:
_addRole_
```javascript
function onRequest(request, response, modules) {
var context = modules.backendContext,
utils = modules.utils,
appKey = context.getAppKey(),
masterSecret = context.getMasterSecret(),
userid = request.body.userid,
roleid = request.body.roleid,
uri = 'https://baas.kinvey.com/user/' + context.getAppKey()+ '/' + userid + '/roles/' + roleid,
authString = "Basic " + utils.base64.encode(appKey + ":" + masterSecret),
requestOptions = {
uri:uri,
headers: {
"Authorization":authString
}
},
auth;
auth = modules.request.put(requestOptions,function(error, res, body){
if (error){
response.error(error);
} else {
response.body = JSON.parse(body);
response.complete(res.status);
}
});
}
```
_deleteRole_
```javascript
function onRequest(request, response, modules) {
var context = modules.backendContext,
utils = modules.utils,
appKey = context.getAppKey(),
masterSecret = context.getMasterSecret(),
userid = request.body.userid,
roleid = request.body.roleid,
uri = 'https://baas.kinvey.com/user/' + context.getAppKey()+ '/' + userid + '/roles/' + roleid,
authString = "Basic " + utils.base64.encode(appKey + ":" + masterSecret),
requestOptions = {
uri:uri,
headers: {
"Authorization":authString
}
},
auth;
auth = modules.request.del(requestOptions,function(error, res, body){
if (error){
response.error(error);
} else {
response.body = "{}";
response.complete(res.status);
}
});
}
```
A written guide explaining the code within the sample application is forthcoming.