Git Product home page Git Product logo

npm-civic-sip-api's Introduction

NPM version NPM downloads node version

Node.js wrapper for the Civic hosted SIP API. For best results, be sure that you're using the latest version.

Please see docs.civic.com for a more details.

Installation

civic-sip-api can be installed from npm:

npm install civic-sip-api --save

Basic Usage

const civicSip = require('civic-sip-api');

const civicClient = civicSip.newClient({
    appId: 'ABC123',
    appSecret: APP_SECRET,
    prvKey: PRV_KEY,
});

civicClient.exchangeCode(jwtToken)
    .then((userData) => {
        // store user data and userId as appropriate
        console.log('userData = ', JSON.stringify(userData, null, 4));
    }).catch((error) => {
        console.log(error);
    });

Example of data returned for a ScopeRequest of BASIC_SIGNUP

userData =  {
    "data": [
        {
            "label": "contact.personal.email",
            "value": "[email protected]",
            "isValid": true,
            "isOwner": true
        },
        {
            "label": "contact.personal.phoneNumber",
            "value": "+1 5556187380",
            "isValid": true,
            "isOwner": true
        }
    ],
    "userId": "c6d5795f8a059ez5ad29a33a60f8b402a172c3e0bbe50fd230ae8e0303609b42"
}

Proxy Usage

There is basic proxy support. The server address and port is set as a url.

rejectUnauthorized Setting this to false is optional and can be used when testing in development and needing to use a self signed cerificate. We do not recommend setting this to false in a production environment as it will compromise security.

const civicSip = require('civic-sip-api');

const civicClient = civicSip.newClient({
    appId: 'ABC123',
    appSecret: APP_SECRET,
    prvKey: PRV_KEY,
    proxy: {
      url: 'http://10.0.0.6:8080',
      rejectUnauthorized: false, // Do not make false in production
    },
});

civicClient.exchangeCode(jwtToken)
    .then((userData) => {
        // store user data and userId as appropriate
        console.log('userData = ', JSON.stringify(userData, null, 4));
    }).catch((error) => {
        console.log(error);
    });

Copyright © 2018 Civic.com

Released under the MIT License, which can be found in the repository in LICENSE.txt.

npm-civic-sip-api's People

Contributors

amycify avatar chriteixeira avatar dankelleher avatar dependabot[bot] avatar dmelosantos avatar flipscholtz avatar iainfra avatar kevinhcolgan avatar mjgaylord avatar simranbentel avatar stewart42 avatar syntaxza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

npm-civic-sip-api's Issues

Python lib

Is there any plan to make official python lib for civic api?

babel-polyfill replaces existing Promise implementation

same as: feathersjs/feathers#510

it is very well described in the above issue so I will not repeat it here ( it would suffice to copy and paste replacing feathers with civic-sip-api )

for others needing a workaround util this is resolved, replace:

global.Promise = require("bluebird")

with

Object.defineProperty(global, "Promise", {
  value:require("bluebird"),
  writable:false
})

Error: Error exchanging code for data: Error: JWT Token containing encrypted data could not be verified at verifyAndDecrypt

Hi,
I'm using civic-sip-api in a Node.Js app for login and every thing was working fine. But today when I tried to login using civic, got the following error.

Error: Error exchanging code for data: Error: JWT Token containing encrypted data could not be verified at verifyAndDecrypt (E:\Projects\BASaaS\branches\dios_phase_2\node_modules\civic-sip-api\dist\index.js:248:13) at Object._callee$ (E:\Projects\BASaaS\branches\dios_phase_2\node_modules\civic-sip-api\dist\index.js:83:48) at tryCatch (E:\Projects\BASaaS\branches\dios_phase_2\node_modules\regenerator-runtime\runtime.js:62:40) at Generator.invoke [as _invoke] (E:\Projects\BASaaS\branches\dios_phase_2\node_modules\regenerator-runtime\runtime.js:296:22) at Generator.prototype.(anonymous function) [as next] (E:\Projects\BASaaS\branches\dios_phase_2\node_modules\regenerator-runtime\runtime.js:114:21) at step (E:\Projects\BASaaS\branches\dios_phase_2\node_modules\babel-runtime\helpers\asyncToGenerator.js:17:30) at E:\Projects\BASaaS\branches\dios_phase_2\node_modules\babel-runtime\helpers\asyncToGenerator.js:28:13 at at process._tickCallback (internal/process/next_tick.js:182:7)

Any help would be greatly appreciated. Thank you.

The server responded with a status of 401

Hi,
I am trying to integrate Civic identity in a node.js application. I am running the application in TEST mode.
However while invoking the login ("BASIC SIGNUP") event it is throwing "Failed to load resource: the server responded with a status of 401 (Unauthorized).
api.civic.com/sip/prod/scopeRequest/qrcode:1"

This is just the login button. Code below:

<title>Login Page</title>
<link rel="stylesheet" href="https://hosted-sip.civic.com/css/civic-modal.min.css">
Log in with Civic
</body>
<script  src="https://hosted-sip.civic.com/js/civic.sip.min.js"></script>
<script>
		var civicSip = new civic.sip({ appId: 'JTfdg1OQX' });
		var button = document.getElementById('signupButton');
		button.addEventListener('click', function () {
		civicSip.signup({ style: 'popup', scopeRequest: civicSip.ScopeRequests.BASIC_SIGNUP });
		});
		 // Listen for data
		civicSip.on('auth-code-received', function (event) {
			// encoded JWT Token is sent to the server
			var jwtToken = event.response;

			// Your function to pass JWT token to your server
			sendAuthCode(jwtToken);
		  });
		 civicSip.on('user-cancelled', function (event) {
			/*
				event:
				{
				  event: "scoperequest:user-cancelled"
				}
			*/
		   });

		  civicSip.on('read', function (event) {
			/*
				event:
				{
				  event: "scoperequest:read"
				}
			*/
		  });

		   // Error events.
		   civicSip.on('civic-sip-error', function (error) {
			  // handle error display if necessary.
			  console.log('   Error type = ' + error.type);
			  console.log('   Error message = ' + error.message);
		   });  
</script>

CivicSip error parsing event data.

I get the error "Error parsing event data: text ..."

We use a metamask extension (https://metamask.io/) for an application that sends messages window.postMessage. CivicSip gives an error on them.
Metamask itself periodically sends such messages. For this reason, it cannot be used CivicSip with this extension.

To reproduce this problem, you can send any message.

window.postMessage("hello there!", "*");

Выделение_169

What do the fields in the intergrate.civic.com UI correspond with

On the civic interrogation site there are three fields

"App ID"

"Public Signing Key"

and

"Public Encryption Key"

I'm guessing that one of these is the private key and the other is the the app secret. Is that correct? Do you happen to know which is which?

Could the documentation be updated to reflect the current nomenclature on the civic site?

"civic' is not defined" civic.sip on Client side with React app

Hi, looks like, I'm unable to access civic global variable, any idea what I can be doing wrong. Thanks
I'm getting this error " Line 4: 'civic' is not defined no-undef "

/public/index.html

<title>React App</title>
<link rel="stylesheet" href="https://hosted-sip.civic.com/css/civic-modal.min.css">
<script src="https://hosted-sip.civic.com/js/civic.sip.min.js"></script>

/CivicLogin.js
import React from 'react';

const CivicLogin = () => {
var civicSip = new civic.sip({ appId: 'myAppID' });
return (

Log in with Civic

);
}
export default CivicLogin;

How to exchange userData?

Hi @slaphead,

The Civic project is pretty amazing. I love that I have the control of my identity instead of some third party. I want to build some application with the SDK. However, I am running into some issue with exchange jwtToken with the server. Here are my codes. Please help!

index.html (Client)
https://gist.github.com/kingstenbanh/f60357f7c69350eaaedb63745c6c061c

app.js (Server)
https://gist.github.com/kingstenbanh/93962392cf42c3f91de3095dab4de7a4

Civic Integrate Config

screen shot 2018-01-08 at 12 30 17 am

Error Output

Magic happens on port 8080
eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJmYzQ3Yzg0NS0xZDI1LTQxNTktOGM2OS03ZjU5YjkyNzMzYTIiLCJpYXQiOjE1MTUzOTY3MTUuNTk1LCJleHAiOjE1MTUzOTg1MTUuNTk1LCJpc3MiOiJjaXZpYy1zaXAtaG9zdGVkLXNlcnZpY2UiLCJhdWQiOiJodHRwczovL2FwaS5jaXZpYy5jb20vc2lwLyIsInN1YiI6IlMxRlhPSTFFRyIsImRhdGEiOnsiY29kZVRva2VuIjoiNmRiZTY2MGQtZTI2YS00M2JmLTljNTMtODIwMGY1ZDFjNGRlIn19.wXEqKYuVoHu5w7u31yHZV-geXbeDJjZmgMhn4OtB9pdE5Ra199hxdzvWVhf1q41c2QT3GtLVywAwJUtb1cQCDQ
HEYHEY Error: 401 Unauthorized
    at needle.then (/Users/kingstenbanh/Documents/Projects/Learning/TestCivic/node_modules/civic-sip-api/index.js:149:17)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:160:7)
error Error: Error exchanging code for data: 401 Unauthorized
    at needle.then.catch (/Users/kingstenbanh/Documents/Projects/Learning/TestCivic/node_modules/civic-sip-api/index.js:168:15)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:160:7)
express deprecated res.send(body, status): Use res.status(status).send(body) instead app.js:37:21

Error: Error exchanging code for data: 401 Unauthorized

Hi all,

I am having an issue with the Civic node package and I am wondering if the issue is on my side or yours. I have double checked all of my credentials and even regenerated my tokens.

civicproxy_1 | appId = BJLbJEmRf
civicproxy_1 | prvKey = 0a26dbf45406d9e7c946af67f7d5afc34665ce7e3ec3e227fdd62c9b540a9add
civicproxy_1 | appSecret = 6c02c5fb6ad2bd0b241f6e471ac4b8b9
civicproxy_1 | authtoken = eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJlYTc3NDRmZS00NjI3LTRlYjgtOTVkYi00NDY2ZTRkYTUyOGIiLCJpYXQiOjE1MjYwNjA0MzAuOTg5LCJleHAiOjE1MjYwNjIyMzAuOTg5LCJpc3MiOiJjaXZpYy1zaXAtaG9zdGVkLXNlcnZpY2UiLCJhdWQiOiJodHRwczovL2FwaS5jaXZpYy5jb20vc2lwLyIsInN1YiI6IkJKTGJKRW1SZiIsImRhdGEiOnsiY29kZVRva2VuIjoiOWFkNzk5MWUtZjE2ZC00MzcxLTg2OTktM2I0ZWQxM2QxOWRkIn19.nDN8E9C1KsXxTUxqgeWtlgmBF3HrWpM7w5Ltll6iKJ_JFN5rh7wCVZayNB9Rp2tGp-gt5NsNal38GS3NhHLSeA
civicproxy_1 | Error: Error exchanging code for data: 401 Unauthorized
civicproxy_1 | at needle.then.catch (/app/node_modules/civic-sip-api/index.js:167:15)
civicproxy_1 | at
civicproxy_1 | at process._tickCallback (internal/process/next_tick.js:182:7)

Any help would be greatly appreciated!

Help using the civicSip on Client side in React app

So the civic documentation suggests using <script src="https://hosted-sip.civic.com/js/civic.sip.min.js"> tag to load the civic global variable but I am unable to access it.
Further the civic-sip-api module needs the private keys to create a constructor which is not really good data to have on the client side of user's browser.
This module is technically the server side for the jwt token access.

Any ideas on how to get around this or an example application in react?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.