Angular 2 + passport-github

60 views
Skip to first unread message

eugene...@gmail.com

unread,
Nov 4, 2017, 12:45:52 AM11/4/17
to Angular and AngularJS discussion
Hello! I've stuck with one problem. I have node.js server (loopback) with REST API and authorisation via github (passport-github module). And I have my Angular application that use REST API of this server. So, can you help me with implementation of this github-passport module in my Angular app? Maybe you have example of implementation problem like that.

Sander Elias

unread,
Nov 4, 2017, 4:03:52 AM11/4/17
to Angular and AngularJS discussion
Hi Eugene

What is your issue? AKAIK there is nothing Angular specific in that flow. Follow the passport sample, and then implement that in your app. If there is something specific to angular, don't hesitate and ask us! Preferably with a running sample.

Regards
Sander

eugene...@gmail.com

unread,
Nov 4, 2017, 5:12:12 AM11/4/17
to Angular and AngularJS discussion
I follow this guide -> https://www.npmjs.com/package/passport-github
And my implementation is:
import { Component, OnInit, Input } from '@angular/core';
import { passport } from 'passport';
import { Strategy } from 'passport-github';

@Component({
 selector: 'app-Callback',
 templateUrl: './Callback.component.html',
 styleUrls: ['./Callback.component.css']
})
export class CallbackComponent implements OnInit {
 
 constructor(){}
 
 getAuth(){
   passport.authenticate('github');
 }

  ngOnInit(): void {
   var GitHubStrategy = Strategy.Strategy;
   passport.use(new GitHubStrategy({
   clientID: "56e8d8ca33270722d3b0",
   clientSecret: "73934a7c16258220808d4b9e22abd379d0c25cc3",
   }, function(accessToken, refreshToken, profile, cb) {
     return cb(null, profile);
   }
 ));

    // passport.serializeUser(function(user, cb) {
   //   cb(null, user);
   // });
   
   // passport.deserializeUser(function(obj, cb) {
   //   cb(null, obj);

   // });

      this.getAuth();
   }      
}

< - Error 









суббота, 4 ноября 2017 г., 11:03:52 UTC+3 пользователь Sander Elias написал:

Sander Elias

unread,
Nov 4, 2017, 5:27:57 AM11/4/17
to Angular and AngularJS discussion
Hi Eugene,

Yeah, that code is not supposed to be in the browser. The code you are showing should be on your server side. Not in the browser. Also, giving your key's away in a public forum is not so smart. If I were you, I would invalidate this combo ASAP.
When you have implemented the above in your server, you then can implement the user input and stuff, and let it communicate with your server, where then the server does the auth. after that is done, you can use the resulting key inside your web part.

Regards
Sander

Reply all
Reply to author
Forward
Message has been deleted
0 new messages