SugarCRM Web Services Rest API Ionic Framework AngularJS - angularjs

I customize the application web sugarCRM to my need and I have to realize a hybrid mobile application using Ionic framework and AngularJS.
I want to make a authentication from the mobile application.
In my folder js/factory/userProvider.js i have this code
app.factory('userProvider', function($rootScope, $http) {
function signIn(User) {
var url = 'The url of the api ';
$http.post(url,Userser).success(function (response) {
console.log(response);
});
return{ signIn: signIn }
}
});
My big problem is that SugarCRM already has web services and I don't know the url to use for the authentication.
In my folder js/controllers/homepageController i have this code :
app
.controller('homepageIndex', function ($scope) { })
.controller('homepageLogin', function ($scope, userProvider) {
$scope.user = {};
$scope.signIn = function (user) { userProvider.signIn(user); }
});
So I want to know how to use the web services of sugarCRM to authenticate in my mobile application.

SugarCRM's URL is specific for each company. To get started in your application, you are going to have to ask the user, the URL, Username and Password.
Once, you have this information you can use oauth to obtain the information needed to process requests. To use oauth you need to POST to SugarCRM URL/rest/v10/oauth2/token

Related

integrating linkedin login with angularjs application

I am new to angular js .I would like to know the procedure to get api key and integrating linked in sign in ,sign up with angularjs application.
You can use LinkedIn SDK to handle authorisation and sing up or sing off users.
Documentation: https://developer.linkedin.com/docs/getting-started-js-sdk
You have to initial SDK. You will need to create an app in your LinkedIn Developer panel. Then you get an API Key there.
Then in your app you have to create a service that will call LinkedIn API.
Something like this:
export class LinkedIn {
constructor($q, $window) {
'ngInject';
this.$q = $q;
this.$window = $window;
};
get() {
let doc = this.$window.document;
let script = doc.createElement('script');
let deferred = this.$q.defer();
script.src = 'http://platform.linkedin.com/in.js';
script.innerHTML = [
'api_key: ' + YOUR_API_KEY,
'authorize: ' + 'true',
'lang: ' + 'en-US',
'onLoad: onLinkedInApiLoad',
'scope: ' + YOUR_APP_SCOPE
].join('\n');
this.$window.onLinkedInApiLoad = () => {
deferred.resolve(this.$window.IN);
};
doc.body.appendChild(script);
return deferred.promise;
};
}
Next you need to decide where and when you want to initial this call. You can do that in .run block or made some middleware to handle it. After that you will receive LinkedIn API object.
When you have got your LinkedIn API object you can request authorisation, check if user has been already logged in and etc. Options are describe in documentation. You can authorise user calling IN.User.authorize(handler || angular.noop) or logout IN.User.logout(handler || angular.noop)
There is also options to do a callback on Event where user log in or log out for example:
IN.Event.on(IN, eventName, callback, callbackScope, extraData);
IN.Event.onOnce(IN, eventName, callback, callbackScope, extraData);
You can use angular module for linkedIn authentication. angular-social-login

I need an help for integrate Stripe in my Ionic Mobile App

I'm developing a Taxi Booking Platform on Mobile Hybrid App with Ionic and Firebase.
I need your help to integrate the payment system with Stripe.
I want to create customers automatically and charge only when a client presses the "PAY" button.
Here's the code I already use:
$scope.addCard = function () {
Stripe.card.createToken($scope.newCard, function stripeResponseHandler(status, response) {
if (response.error) {
Toast.error(response.error.message);
} else {
// response contains id and card, which contains additional card details
var token = response.id;
StripeHttp.post('https://api.stripe.com/v1/customers/' + customerId + '/sources', {
source: token
}).success(function (data, status, headers, config) {
getCards(customerId);
console.log(reponse.id)
}).error(function (data, status, headers, config) {
Toast.error("Add cards fail. " + status + data);
});
}
});
};
As I see from your code, you are not distinguishing between the client-side and server-side.
The code you have displayed should be put on the server, and not in your Ionic app.
There are two ways to overcome your issue:
Host your own Server Side and make HTTP calls from your Ionic app
Send HTTP calls from your Ionic app to an already hosted and free payment server like the Stripe Payments API
As for option 2, here are two templates that already integrate and explain how to do that (elaborated docs):
If you are interested in an Ionic 1.x template to integrate Stripe,
then have a look at this starter.
If you are interested in an Ionic 2.x template to integrate Stripe,
then have a look at this starter.

refreshing user.is_authenticated with angular and django rest framework

I'm using django rest framework on the backend and angularjs on the frontend. The problem is the login, in angular I do:
function ($scope, $http, User) {
$scope.login = function (user) {
$http.post('/login/', user)
.then(function (response, status) { // success callback
console.log("success");
console.log(response);
}, function(response) { // error callback
console.log("error");
console.log(response);
})
}
}
then in my views.py I do:
def login_view(request):
user = authenticate(username=request.data['username'], password=request.data['password'])
if user is not None:
login(request, user)
return HttpResponse(status=200)
return HttpResponse(status=400)
But in my home template which is the only django template that I use, the rest is pure html since I use ui-router with state view, so the {% if user.is_authenticated %} won't get updated and I have to refresh the page manually. Is there any solution to make the 'if' statement in the template to be trigger without refreshing all the page, or any better solution to make a login system in my website?
Thank you.
You should not use Django's templatescripts in AngularJS.
AngularJS is a SPA. Django's templatescripts does not work well with SPAs.
You need to create your client logic in javascript only.
This can be done by creating a server endpoint that returns true if a given user is authenticated.

What are the best practices for consuming ASP.NET Web Api with oAuth in Ionic Framework?

Summary:
Suppose I have a ASP.NET WebAPI2 Application as my back-end and for security it uses oAuth (bearer access tokens). Now i want to consume this Web API in my Ionic Application ( which uses AngularJS). What are the best practices to deal with the authorization and retrieval and refreshing access tokens in Ionic Framework?
More info:
Let's suppose i have +100 different AJAX calls to my web api. I want the functionality that if the server challenged an authentication (i.e no access token or it is expired), then i show the login form and eventually get the access token and save it for subsequent calls. And also somehow i should send the access token along with every other request. Obviously i can't write some code and duplicate it for each and every request that need authorization. So i'm looking for the best practices/implementations to handle authentication situations like this in Ionic Framework (AngularJS). Thanks in advance for any help.
You can use AngularJS interceptor for this task, it will be vary similar to the code below:
app.factory('authInterceptorService', ['$q', '$location', 'localStorageService', function ($q, $location, localStorageService) {
var authInterceptorServiceFactory = {};
var _request = function (config) {
config.headers = config.headers || {};
var authData = localStorageService.get('authorizationData');
if (authData) {
config.headers.Authorization = 'Bearer ' + authData.token;
}
return config;
}
var _responseError = function (rejection) {
if (rejection.status === 401) {
$location.path('/login');
}
return $q.reject(rejection);
}
authInterceptorServiceFactory.request = _request;
authInterceptorServiceFactory.responseError = _responseError;
return authInterceptorServiceFactory;
}]);
I have written detailed blog post on how to send access token from AngularJS app to Web Api back-end in a centralized place that you do not need to duplicate any code. You can check the post title "AngularJS Token Authentication using ASP.NET Web API 2, Owin, and Identity"

Cross origin request not working in Cordova with AngularJS

I am developing mobile application with Cordova tool and using angularJS.
I have written services in different project. I need to call those services in my cordova application, Whenever I try to call service it giving me Error:
net::ERR_CONNECTION_REFUSED
This might be browser issue or headers issue. Please suggest me right way to solve this issue.
Currently I am running service on localhost, and It is working perfectly when I call them from fiddler.
I have also open CORS in service project.
JodoModule.service("AccountSrv", function ($http) {
this.signUp = function (user) {
var SignUpReq = {
method: 'GET',
url: 'http://localhost:62676/api/Account/signin'
}
$http(SignUpReq).success(function () { alert("Succ"); }).error(function (data) { alert("Err = " + JSON.stringify(data)); });
}
});
and my controller is,
JodoModule.controller("AccountCtrl", function ($scope, AccountSrv) {
$scope.signUp = function () {
AccountSrv.signUp();
}
});
You can disable cross domain proxies in the emulator as a workaround.

Resources