This file contains 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
using Microsoft.AspNet.Identity.EntityFramework; | |
using System; | |
using System.Collections.Generic; | |
using System.Data.Entity; | |
using System.Linq; | |
using System.Web; | |
using TestWebApp.Infrastructure; | |
using TestWebApp.Models; | |
using TestWebApp.Repositories; |
This file contains 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
public class InitializeWithDefaultData : DropCreateDatabaseAlways<AuthContext> | |
{ | |
protected override void Seed(AuthContext context) | |
{ | |
using (var store = new RoleStore<IdentityRole>(context)) | |
{ | |
using (var manager = new RoleManager<IdentityRole>(store)) | |
{ | |
manager.Create(new IdentityRole("admin")); | |
manager.Create(new IdentityRole("student")); |
This file contains 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
public class AuthContext : IdentityDbContext<ApplicationUser> | |
{ | |
public AuthContext() : base("AuthContext") | |
{ | |
Database.SetInitializer(new InitializeWithDefaultData()); | |
} | |
protected override void OnModelCreating(DbModelBuilder modelBuilder) | |
{ | |
base.OnModelCreating(modelBuilder); |
This file contains 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
const Hapi = require('hapi'); | |
const Inert = require('inert'); | |
const Vision = require('vision'); | |
const HapiSwagger = require('hapi-swagger'); | |
const Pack = require('./package'); | |
const server = Hapi.Server({ | |
host: 'localhost', | |
port: 3000 | |
}); |
This file contains 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/twitter') | |
.post((req, res, next) => { | |
request.post({ | |
url: `https://api.twitter.com/oauth/access_token?oauth_verifier`, | |
oauth: { | |
consumer_key: 'KEY', | |
consumer_secret: 'SECRET', | |
token: req.query.oauth_token | |
}, | |
form: { oauth_verifier: req.query.oauth_verifier } |
This file contains 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/twitter/reverse') | |
.post(function(req, res) { | |
request.post({ | |
url: 'https://api.twitter.com/oauth/request_token', | |
oauth: { | |
oauth_callback: "http%3A%2F%2Flocalhost%3A3000%2Ftwitter-callback", | |
consumer_key: 'KEY', | |
consumer_secret: 'SECRET' | |
} | |
}, function (err, r, body) { |
This file contains 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
logout = () => { | |
this.setState({isAuthenticated: false, token: '', user: null}) | |
}; |
This file contains 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
onSuccess = (response) => { | |
const token = response.headers.get('x-auth-token'); | |
response.json().then(user => { | |
if (token) { | |
this.setState({isAuthenticated: true, user: user, token: token}); | |
} | |
}); | |
}; | |
onFailed = (error) => { |
This file contains 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() { | |
super(); | |
this.state = { isAuthenticated: false, user: null, token: ''}; | |
} |
This file contains 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
//token handling middleware | |
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; | |
} |
NewerOlder