npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-authentication-service

v1.1.8

Published

Authentication Service For Angular 4

Downloads

19

Readme

AngularAuthenticationService

This project was generated with Angular CLI version 1.4.1.

##Install with NPM $ npm install angular-authentication-service

##main.ts

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AuthenticationServiceModule } from './app/app.module';
import { environment } from './environments/environment';

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AuthenticationServiceModule).catch(err => console.log(err));

##app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { routing } from './app.routing';
import { LocalStorageModule } from 'angular-2-local-storage';
import { HomeComponent } from './home/home.component';
import { HttpIntercept,AuthIntercept,AuthenticationService,GlobalVarsService,LogIn,User } from 'angular-authentication-service';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';

@NgModule({
  declarations: [
    AppComponent,
    HomeComponent
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    routing,
    LocalStorageModule.withConfig({
      prefix: 'MyApp',
      storageType: 'localStorage'
    })
  ],
  exports:[],
  providers: [
    LogIn,
    User,
    AuthIntercept,
    GlobalVarsService,
    AuthenticationService,
    {
      provide: HTTP_INTERCEPTORS,
      useClass: HttpIntercept,
      multi: true,
    }
  ],
  bootstrap: [AppComponent]
})

export class AppModule { 
  

}

##Component Module Usage

import { Component, OnInit } from '@angular/core';
import { Routes, RouterModule, Router } from '@angular/router';
import { Subscription } from 'rxjs/Subscription';
import { AuthenticationService, User, LogIn, GlobalVarsService } from 'angular-authentication-service';

import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
// Observable class extensions
import 'rxjs/add/observable/of';

// Observable operators
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/debounceTime';
import 'rxjs/add/operator/distinctUntilChanged';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})

export class AppComponent {
  title = 'app';
  user: User;
  credentials: LogIn;

  constructor(private router: Router,private authenticationservice: AuthenticationService) {
    this.authenticationservice.AuthURI = '/api/authenticate';
  }

  ngOnInit(): void {
    this.user = new User;
    this.credentials = new LogIn;

    this.credentials.username = "username";
    this.credentials.password = "password";
    this.credentials.app = "MyAppName";

    this.authenticationservice.login(this.credentials).subscribe(data => {
      if (data) {
        this.user = data;
        localStorage.setItem('token', data.access_token);
      } else {
        localStorage.setItem('token', '');
      }
    }, err => {
      console.log('error: ', err);
    });
  }

}

#Server Side ##routes.js

const express = require('express');
const router = express.Router();
var request = require('request');
var http = require('http');
var https = require('https');
var path = require('path');
var fs = require('fs-extra');
var config = require('./config')

var app = null
var protocol = null

var certfolder = path.join(__dirname, 'certificates');

router.post('/authenticate', (req, res) => {
    var str = '';

    //API listening on port 8000
    var options = {
        host: 'localhost',
        path: '/authenticate',
        port: '8000',
        method: 'POST',
        headers: {
            'Content-Type': 'application/json;charset=UTF-8'
        }
    }

    var request = http.request(options, function (response) {

        response.on('data', function (chunk) {
            str += chunk;
        });

        response.on('end', function () {
            var obj = null;

            if (response.statusCode === 200) {
                obj = JSON.parse(str);
                return res.status(200).send(obj);
            } else {
                return res.status(response.statusCode).send(response.statusMessage);
            }
        });
    });

    request.write(JSON.stringify(req.body));
    request.end();

});

module.exports = router;

##server.js

var compression = require('compression')
var config = require('./config')
var express = require('express')
var http = require('http')
var https = require('https')
var bodyParser = require('body-parser')
var path = require('path')

const router = express.Router()
const api = require('./routes')

var app = express()
app.use(compression())

app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(express.static(path.join(__dirname, 'dist')))

http.globalAgent.maxSockets = 100
var server = http.createServer(app)

app.use(express.static(__dirname + '/dist'))

app.use('/api', api);

app.use(function (req, res) {
    res.sendFile(__dirname + '/dist/index.html')
});

app.get('/', (req, res) => {
    res.sendFile(path.join(__dirname, './dist/index.html'))
});

server.listen(8043, function () {
  console.log('Express server listening on port 8043')
  console.log('Press CTRL+C to exit.')
})