コード例 #1
0
    def test_get_user(self):
        # just creating a service out of thin air
        ci = CenterIdentity(
            'L38yoTWooppsQD4FubNfg9BmhZSvec5jnQMxLKD3si2GHA3g9gJk',
            'test_service')
        ci.service.domain = self.domain

        # instantiate a user from a dict that should come from another center identity library
        # you should not have to create a dict manually
        # should be CenterIdentity.user(data)
        post_data_for_add = {
            'username':
            '******',
            'username_signature':
            'MEUCIQDMGiwL5unMr4joJTWaNudo0NeIqGIkK/+DeQNK3wdeqgIgIWmqe2vILDcA1TPxNDuXJavt6K5MEUtJgZRF4q7LB1M=',
            'public_key':
            '030727d998882093dea970377f50e5d203ac805003e9c9b390aed3ae6bda05460d'
        }
        result = ci.add_user(post_data_for_add)

        post_data_for_get = {
            'username_signature':
            'MEUCIQDMGiwL5unMr4joJTWaNudo0NeIqGIkK/+DeQNK3wdeqgIgIWmqe2vILDcA1TPxNDuXJavt6K5MEUtJgZRF4q7LB1M=',
        }
        user = ci.get_user(post_data_for_get)
        self.assertIsInstance(user, User)
        self.assertEqual(user.username, 'test_service')
        self.assertEqual(
            user.username_signature,
            'MEUCIQDMGiwL5unMr4joJTWaNudo0NeIqGIkK/+DeQNK3wdeqgIgIWmqe2vILDcA1TPxNDuXJavt6K5MEUtJgZRF4q7LB1M='
        )
        self.assertEqual(
            user.public_key,
            '030727d998882093dea970377f50e5d203ac805003e9c9b390aed3ae6bda05460d'
        )
コード例 #2
0
    def test_authenticate_user(self):
        # instantiate a user from a dict that should come from another center identity library
        # you should not have to create a dict manually
        # should be CenterIdentity.user(data)
        ci = CenterIdentity(
            'L38yoTWooppsQD4FubNfg9BmhZSvec5jnQMxLKD3si2GHA3g9gJk',
            'test_service')
        ci.service.domain = self.domain
        post_data = {
            'username':
            '******',
            'username_signature':
            'MEUCIQDMGiwL5unMr4joJTWaNudo0NeIqGIkK/+DeQNK3wdeqgIgIWmqe2vILDcA1TPxNDuXJavt6K5MEUtJgZRF4q7LB1M=',
            'public_key':
            '030727d998882093dea970377f50e5d203ac805003e9c9b390aed3ae6bda05460d',
            'session_id_signature':
            'MEUCIQDMGiwL5unMr4joJTWaNudo0NeIqGIkK/+DeQNK3wdeqgIgIWmqe2vILDcA1TPxNDuXJavt6K5MEUtJgZRF4q7LB1M='
        }

        session_id = 'test_service'

        result = ci.authenticate(session_id, post_data, hash_session_id=False)
        self.assertIsInstance(result, User)
コード例 #3
0
    def test_user_from_dict(self):

        user = CenterIdentity.user_from_dict({
            'username':
            '******',
            'username_signature':
            'MEUCIQDMGiwL5unMr4joJTWaNudo0NeIqGIkK/+DeQNK3wdeqgIgIWmqe2vILDcA1TPxNDuXJavt6K5MEUtJgZRF4q7LB1M=',
            'public_key':
            '030727d998882093dea970377f50e5d203ac805003e9c9b390aed3ae6bda05460d'
        })
        self.assertEqual(user.username, 'test_service')
        self.assertEqual(
            user.username_signature,
            'MEUCIQDMGiwL5unMr4joJTWaNudo0NeIqGIkK/+DeQNK3wdeqgIgIWmqe2vILDcA1TPxNDuXJavt6K5MEUtJgZRF4q7LB1M='
        )
        self.assertEqual(
            user.public_key,
            '030727d998882093dea970377f50e5d203ac805003e9c9b390aed3ae6bda05460d'
        )
コード例 #4
0
from uuid import uuid4
from flask import Flask, request, session
from flask.templating import render_template
from centeridentity.api import CenterIdentity

app = Flask(__name__)

ci = CenterIdentity('YOUR_CENTER_IDENTITY_API_KEY',
                    'YOUR_CENTER_IDENTITY_USERNAME')


@app.route('/')
def index():
    if not session.get('uuid'):
        session['uuid'] = str(uuid4())
    return render_template('index.html', session_id=session['uuid'])


@app.route('/create-customer', methods=["POST"])
def create_customer():
    result = ci.add_user(request.json)
    return result


@app.route('/sign-in', methods=["POST"])
def sign_in():
    user = ci.authenticate(session['uuid'], request.json)
    session['user'] = user.to_dict
    return session['user']

コード例 #5
0
    def test_generate_service(self):
        service = CenterIdentity.generate('test_service')

        self.assertIsNotNone(service)