CompoundJS and passport support - javascript

I'm facing this problem with compound passport. I've already followed the steps from the guide but I cannot get this working when I try to access /auth/github.
Any tips?
GET /auth/github controller: auth action: github
Params: {"controller":"auth","action":"github"}
>>> perform github
Error: Undefined action auth#github(/auth/github)
at Object.FlowControl.call.context.innerNext (/Users/javiermanzanomorilla/Development/workspace/authapp/node_modules/compound/node_modules/kontroller/lib/flow-control.js:67:27)
at Array.FlowControl.call.collection.forEach.queue.push.ctl.context.inAction [as 1] (/Users/javiermanzanomorilla/Development/workspace/authapp/node_modules/compound/node_modules/kontroller/lib/flow-control.js:139:28)
at run (/Users/javiermanzanomorilla/Development/workspace/authapp/node_modules/compound/node_modules/kontroller/lib/flow-control.js:102:27)
at Array.FlowControl.call.action [as 0] (/Users/javiermanzanomorilla/Development/workspace/authapp/node_modules/compound/node_modules/kontroller/lib/flow-control.js:60:13)
at run (/Users/javiermanzanomorilla/Development/workspace/authapp/node_modules/compound/node_modules/kontroller/lib/flow-control.js:102:27)
at FlowControl.call.compiledAction.(anonymous function) (/Users/javiermanzanomorilla/Development/workspace/authapp/node_modules/compound/node_modules/kontroller/lib/flow-control.js:90:9)
at Controller.call (/Users/javiermanzanomorilla/Development/workspace/authapp/node_modules/compound/node_modules/kontroller/lib/flow-control.js:49:16)
at Controller.call (/Users/javiermanzanomorilla/Development/workspace/authapp/node_modules/compound/node_modules/kontroller/lib/flow-control.js:93:10)
at Controller.perform (/Users/javiermanzanomorilla/Development/workspace/authapp/node_modules/compound/node_modules/kontroller/lib/flow-control.js:18:10)
at ControllerBrigde.callControllerAction (/Users/javiermanzanomorilla/Development/workspace/authapp/node_modules/compound/lib/controller-bridge.js:95:9)

i think that you havn't init the passport.
if you are using compound-passport you have to initialize it by calling the init function in config/environment.
var pass_connect=require('compound-passport');
app.configure(function(){
....
//init the compound passport
pass_connect.init(compound);
app.use(app.router);
});
case if you want to initialize it manualy you have to call those two methods :
var passport=require('passport');
var Strategy = require('passport-github').Strategy;
passport.use(new Strategy({
clientID: conf.github.clientID,
clientSecret: conf.github.secret,
callbackURL: conf.baseURL + 'auth/github/callback'
}, exports.callback));
app.get('/auth/github',
passport.authenticate('github'));
app.get('/auth/github/callback',
passport.authenticate('github', { failureRedirect: '/' }),
exports.redirectOnSuccess);
sorry for my english.

Related

Azure B2C - MSAL callback method doesn't call the method which return the promise?

In the Azure B2C in the authCallback() the ItWillCallPromise is not getting called. Is it as per the design or I am doing something wrong. Also, if its not possible as per the design is there a workaround to call the ItWillCallPromise method ?
function initializeAuthAgent() {
var authConfig = Config();
authAgent = new Msal.UserAgentApplication({
auth: {
clientId: authConfig.clientId,
authority: authConfig.authority,
validateAuthority: false,
postLogoutRedirectUri: '/index.html'
},
cache: {
cacheLocation: 'sessionStorage'
}
});
authAgent.handleRedirectCallback(authCallback);
authCallback(){
ItWillCallPromise.then(function(ID){ console.log(ID)};
}
ItWillCallPromise = function(){
return fetch(url).then(function(a){ return a.ID;}
}
Not sure if it's a typo in your code snippet. But as per that, it's not getting called because you are not calling :). () is missing.
ItWillCallPromise().then(function(ID){ console.log(ID)};
In MSAL.js v1, handleRedirectCallback will only be invoked when there is a hash response in the url (as a result of invoking loginRedirect or acquireTokenRedirect). Depending on the business logic of your app, you can first check if there is a hash in the url (before instantiating UserAgentApplication, which will clear the hash if one was present) and then check if a user is logged in, and then invoke ItWillCallPromise directly.
For example:
function initializeAuthAgent() {
var authConfig = Config();
var hasHash = !!window.location.hash;
authAgent = new Msal.UserAgentApplication({
auth: {
clientId: authConfig.clientId,
authority: authConfig.authority,
validateAuthority: false,
postLogoutRedirectUri: '/index.html'
},
cache: {
cacheLocation: 'sessionStorage'
}
});
var isLoggedIn = !!authAgent.getAccount();
// If there is already a logged in user and were not returning from a redirect operation, immediately call ItWillCallPromise.
if (isLoggedIn && !hasHash) {
ItWillCallPromise()
}
authAgent.handleRedirectCallback(authCallback);
authCallback(){
ItWillCallPromise.then(function(ID){ console.log(ID)};
}
ItWillCallPromise = function(){
return fetch(url).then(function(a){ return a.ID;}
}
MSAL.js v2 (aka #azure/msal-browser on npm) makes this easier, as handleRedirectPromise (which replaces handleRedirectCallback) is invoked on every page load. More details: https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/v1-migration.md

Loading Keycloak config from URL

The Keycloak 3.2 Javascript Adapter documentation says you can instantiate the keycloak object with :
var keycloak = Keycloak('http://localhost:8080/myapp/keycloak.json'));
But when I try to do so, it looks like my keycloak.config file is not propertly set as I end up with :
Uncaught TypeError: Cannot read property 'charAt' of undefined
at getRealmUrl (keycloak.js:482)
at Keycloak.kc.createLoginUrl (keycloak.js:233)
at Object.login (keycloak.js:897)
at Keycloak.kc.login (keycloak.js:205)
at doLogin (keycloak.js:121)
at onLoad (keycloak.js:144)
at Object.processInit [as successCallback] (keycloak.js:187)
at Object.setSuccess (keycloak.js:771)
at XMLHttpRequest.req.onreadystatechange (keycloak.js:598)
at XMLHttpRequest.wrapFn [as __zone_symbol___onreadystatechange] (zone.js:1056)
Yet, when I access http://localhost:8080/myapp/keycloak.json with my browser I get :
{
url: 'http://keycloak-server/auth',
realm: 'myrealm',
clientId: 'myapp'
}
and if I instantiate the keycloak object with
var keycloak = Keycloak({
url: 'http://keycloak-server/auth',
realm: 'myrealm',
clientId: 'myapp'
});
everything works fine.
Is this a Keycloak bug, or is there anything I'm missing ?
Keycloak uses a different format whether you load the config from its URL or straight into the constructor...
If you load it via its URL, the format has to be :
{
auth-server-url: 'http://keycloak-server/auth',
realm: 'myrealm',
resource: 'myapp'
}
and not
{
url: 'http://keycloak-server/auth',
realm: 'myrealm',
clientId: 'myapp'
}

Passport Local strategy not called

I use angularJS+passport to perform user authentication and hence, i set up these below.
HTML:
<div ng-controller="logincontroller">
<form>
Email:<input type="text" ng-model="user.email"/>
Password:<input type="password" ng-model="user.password"/>
<div ng-click=loginUser()>Submit</div>
</form>
</div>
In client side javascript:
app.controller('logincontroller',function($scope,$http){
$scope.loginUser=function(){
$http.post('/loginUser',JSON.stringify($scope.user));
}
})
ON app.js
var bodyParser = require('body-parser');
var cookieParser=require('cookie-parser');
var passport=require('passport');
var LocalStrategy=require('passport-local').Strategy();
var session=require('express-session');
app.use(express.session({secret:"flibbertygibbit"}));
app.use(cookieParser());
app.use(passport.initialize());
app.use(passport.session());
app.use(bodyParser.json());
passport.use(new LocalStrategy(
{usernameField: 'user.email',
passwordField: 'user.password',
passReqToCallback: true
},
function(username,password,done){
console.log("am here"+username+" "+password);
}
))
app.post('/loginUser',passport.authenticate('local'));
The problem i face is the Local strategy isnot being called at all and all I get Typerror: Local strategy requires a verify callback. I ain't sure where i went wrong, being novice at it. Please help.
The error you're getting is caused by this:
var LocalStrategy=require('passport-local').Strategy();
^^
You're calling the Strategy class without any arguments, so this results in the error. You want to store a reference to the class itself, like this:
var LocalStrategy=require('passport-local').Strategy;
Also, because you're setting passReqToCallback : true, the verification callback will take four arguments, not three. It should look like this:
function(req, username, password, done) { ... }

Ember.js more than one param in url

I have a route /changepassword and I need to add to it 2 params: iduser and resetcode. To look like this: /changepassword?iduser=123&resetcode=foo
I read other things related to this (1, 2) but I couldn't figure this out. I don't have any experience in ember and I was ask to do some modifications where I work. We are using ember 1.5.1
I tried this but it's throwing me this: Uncaught Error: Assertion Failed: Error: Assertion Failed: The URL '/changepassword?test1=aaasd' did not match any routes in your application
[EDIT]
Thanks to #GJK, I know that what I need is query params, no path params.
Now, my code looks like this:
Routes:
module.exports = App.Router.map ->
...
...
#resource('change_password', path: '/changepassword')
Controller:
module.exports = App.ChangePasswordController = Ember.Controller.extend
needs: ['config', 'viewport', 'application']
queryParams: ['test']
test: null
...
...
But, when I access http://localhost:3333/#/changepassword?test=foo is transitioning to: http://localhost:3333/#/changepassword
[OLD]
This are my routes:
module.exports = App.Router.map ->
#resource 'index', path: '/', ->
#resource('account_sign_up', path: '/signup')
#resource('unsubscribe', path: '/unsubscribe')
#resource('change_password', path: '/changepassword/:test1/:test2')
Any help? Thanks!
There are two possible ways to do this:
1) Use the params variable with multiple parameters:
#resource('change_password', path: '/changepassword/:iduser/:resetcode')
model : function (params) {
console.log(params.iduser);
console.log(params.resetcode);
}
2) Use the http://guides.emberjs.com/v1.10.0/routing/query-params/ (which I'm not sure is available for 1.5)..so I didn't include an example..

Angular JS - Connect to Woocommerce OAuth v1

I'm trying to (unsuccesfully) authenticate myself to the rest service.
I was tryng this library to create all the params listed here and I'm creating the request in this way:
$scope.oauth = new OAuth({
consumer: {
public: 'ck_d34c32d9c7f6fc1ddb6e85879fc4de89',
secret: 'cs_1867e5e54ce054dde7cf463ad78ee6f9'
},
signature_method: 'HMAC-SHA1'
});
var request_data = {
url: 'http://belfiore.link-me.it/wc-api/v1/orders',
method: 'GET',
}
$scope.data = $scope.oauth.authorize(request_data);
$scope.url = rawurlencode(request_data.url) + "&" +
"oauth_consumer_key"+"%3D"+rawurlencode($scope.data.oauth_consumer_key)+
"%26"+"oauth_nonce"+"%3D"+rawurlencode($scope.data.oauth_nonce)+
"%26"+"oauth_signature_method"+"%3D"+rawurlencode($scope.data.oauth_signature_method)+
"%26"+"oauth_timestamp"+"%3D"+rawurlencode($scope.data.oauth_timestamp)+
"%26"+"oauth_signature"+"%3D"+rawurlencode($scope.data.oauth_signature);
var call = $http.get($scope.url);
call.success(function(res) {
console.log(res);
});
call.error(function(res) {
console.log(res);
});
but i keep getting this answer:
"Cannot GET /http%3A%2F%2Fbelfiore.link-me.it%2Fwc-api%2Fv1%2Forders&oauth_consumer_key%3Dck_d34c32d9c7f6fc1ddb6e85879fc4de89%26oauth_nonce%3DwkeLtFTh6WAuxDQGqnpzxAWYOQiHnHSr%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D10%26oauth_signature%3DjFhPbKHnvMEvYf20w1vN3TAV5Ds%3D"
Any help? I googled out to find some tutorial or angular ready library fot OAuth1 but I found nothing...
thanks in advance
I'm the author of the oauth-1.0a lib
I did not try angularjs yet but just a quick glance, please follow the below code:
$http({
url: request_data.url,
method: request_data.method,
params: $scope.oauth.authorize(request_data)
});
rawurlencode is a php function, however,you should use javascript function encodeURIComponent to replace it.

Categories

Resources