This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bitbucketLogin() { | |
| let key = 'secret_key'; | |
| window.location = | |
| `https://bitbucket.org/site/oauth2/authorize?client_id=${key}&response_type=token`; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| componentDidMount() { | |
| let params = window.location.hash.split('&'); | |
| if (params.length > 0 && params[0].startsWith('#access_token=')) { | |
| let key = decodeURIComponent(params[0].replace('#access_token=', '')); | |
| this.authenticate(key); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| constructor(props) { | |
| super(props); | |
| this.client = axios.create({ | |
| baseURL: 'http://localhost:4000/api/v1/', | |
| timeout: 3000, | |
| headers: {'Accept': 'application/json'}, | |
| }); | |
| this.state = {key: '', isAuthenticated: false, user: null, token: ''}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| authenticate(key) { | |
| let that = this; | |
| this.client.post('/auth/bitbucket', { | |
| access_token: key | |
| }) | |
| .then(response => { | |
| this.client = axios.create({ | |
| baseURL: 'http://localhost:4000/api/v1/', | |
| timeout: 3000, | |
| headers: {'x-auth-token': response.headers['x-auth-token']} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var data = "data that we want to hash"; | |
| var crypto = require('crypto'); | |
| crypto.createHash('sha1').update(data).digest("hex"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // enable cors | |
| var corsOption = { | |
| origin: true, | |
| methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', | |
| credentials: true, | |
| exposedHeaders: ['x-auth-token'] | |
| }; | |
| app.use(cors(corsOption)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var getCurrentUser = function(req, res, next) { | |
| User.findById(req.auth.id, function(err, user) { | |
| if (err) { | |
| next(err); | |
| } else { | |
| req.user = user; | |
| next(); | |
| } | |
| }); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| router.route('/auth/facebook') | |
| .post(passport.authenticate('facebook-token', {session: false}), function(req, res, next) { | |
| if (!req.user) { | |
| return res.send(401, 'User Not Authenticated'); | |
| } | |
| // prepare token for API | |
| req.auth = { | |
| id: req.user.id | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var authenticate = expressJwt({ | |
| secret: 'my-secret', | |
| requestProperty: 'auth', | |
| getToken: function(req) { | |
| if (req.headers['x-auth-token']) { | |
| return req.headers['x-auth-token']; | |
| } | |
| return null; | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var createToken = function(auth) { | |
| return jwt.sign({ | |
| id: auth.id | |
| }, 'my-secret', | |
| { | |
| expiresIn: 60 * 120 | |
| }); | |
| }; | |
| var generateToken = function (req, res, next) { |