Skip to content

Example backend for authentication token generation in Python. Demonstrates how to integrate Sinch with a custom user database.

License

Notifications You must be signed in to change notification settings

EricAdonis/python-backend-sample

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 

Repository files navigation

Sinch authentication token backend example

This demonstrates a basic partner backend for generating authentication tokens. In this example the user database is not persistent: Only for demonstrational purpose!

Requirements

Python >= 2.7.X | >= 3.X
Tornado >= 4.0.1
pip (python package manager)

Installation & start

pip install tornado #or upgrade
nano backend-example.py #or other editor - set your key & secret
./backend-example.py

Note: default port is 2048

Note: If you have the JS SDK release bundle, you can proceed with running the SinchAUTHsample. The code below serves as a complete reference.

Usage

The demo backend expose two resources:

  • /register - Register user
  • /login - Authentication as user

Send a JSON object to either of these resources to either register a user or authenticate as a user.

Example JSON object: {username: 'someUserName', password: 'highlySecurePwd'}

Note: You can't authenticate as a user before it's registered!

Use backend w. Sinch JS SDK

var loginObj = JSON.stringify({'username': 'magnus', 'password': 'superSecure'});

$.post('http://localhost:2048/login', loginObj, {}, "json")
	.done(function(authTicket) {

		sinchClient2.start(authTicket)
			.then(function() {
				console.log('SUCCESS!');
			})
			.fail(function(error) {
				console.error('SinchClient fail!');
			})
			.done();
	})
	.fail(function(error) {
		console.error('Auth failure!');
	});

Using Sinch JS SDK and jQuery

About

Example backend for authentication token generation in Python. Demonstrates how to integrate Sinch with a custom user database.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%