Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
angular-stormpath
Advanced tools
Angular Components for integrating with Stormpath's API
Angular SDK for Stormpath's API. If you're looking for AngularJS support, please see stormpath-sdk-angularjs.
Install through npm:
npm install --save angular-stormpath
Then use it in your app like so:
import { Component } from '@angular/core';
import { Observable } from 'rxjs';
import { Account, Stormpath } from 'angular-stormpath';
@Component({
selector: 'app-root',
template: `<div *ngIf="(user$ | async)" class="row text-center">
<h2 class="">
Welcome, ({{ ( user$ | async ).fullName }}).
</h2>
<hr/>
<h4>What would you like to do?</h4>
<ul class="nav nav-pills nav-stacked text-centered">
<li role="presentation" (click)="logout()"><a href="#">Logout</a></li>
</ul>
</div>
<sp-authport></sp-authport>`,
providers: [Stormpath]
})
export class AppComponent {
private user$: Observable<Account | boolean>;
private loggedIn$: Observable<boolean>;
private login: boolean;
private register: boolean;
constructor(public stormpath: Stormpath) {}
ngOnInit() {
this.login = true;
this.register = false;
this.user$ = this.stormpath.user$;
this.loggedIn$ = this.user$.map(user => !!user);
}
showLogin() {
this.login = !(this.register = false);
}
showRegister() {
this.register = !(this.login = false);
}
logout() {
this.stormpath.logout();
}
}
You may also find it useful to view the demo source.
To override the endpoint prefix or URIs for the various endpoints, you can modify the defaults in StormpathConfiguration.
For example, to override the endpoint prefix and /me
URI in demo.module.ts, change it to the following:
export function stormpathConfig(): StormpathConfiguration {
let spConfig: StormpathConfiguration = new StormpathConfiguration();
spConfig.endpointPrefix = 'http://api.mycompany.com';
spConfig.meUri = '/account';
return spConfig;
}
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, StormpathModule],
bootstrap: [AppComponent],
providers: [{
provide: StormpathConfiguration, useFactory: stormpathConfig
}]
})
export class DemoModule {
}
If your Angular app is on a different domain than your endpoints, OAuth will be used for login/logout. The access token will be stored in localStorage under the name stormpath:token
and it will be automatically added as an Authorization
header when you send HTTP requests to your /me
endpoint.
If you'd like to add this header to additional URLs, you'll need to add them as follows:
let config: StormpathConfiguration = new StormpathConfiguration();
config.autoAuthorizedUris.push(new RegExp('http://localhost:3000/myapi/*)');
To override templates, you can use the customTemplate
attribute on a component. Below is an example of app.component.ts with a custom <sp-authport>
and <login-form>
:
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Stormpath, StormpathErrorResponse, Account, LoginFormModel } from 'angular-stormpath';
@Component({
selector: 'demo-app',
template: `
<div class="container">
<br/>
<br/>
<div *ngIf="(user$ | async)" class="row text-center">
<h2 class="">
Welcome, ({{ ( user$ | async ).fullName }}).
</h2>
<hr/>
<ul class="nav nav-pills nav-stacked text-centered">
<li role="presentation" (click)="logout(); false"><a href="">Logout</a></li>
</ul>
</div>
<template #loginform>
<div *ngIf="error" class="alert alert-danger">{{error}}</div>
<form>
<label for="email">Email</label>
<input id="email" name="login" type="text" [(ngModel)]="loginFormModel.login">
<label for="passwordField">Password</label>
<input id="passwordField" name="password" type="password" [(ngModel)]="loginFormModel.password">
<button (click)="login()">Login</button>
</form>
</template>
<template #authport>
<div *ngIf="(user$ | async) === false">
<h2>Sign In</h2>
<login-form [customTemplate]="loginform"></login-form>
</div>
</template>
<sp-authport [customTemplate]="authport"></sp-authport>
</div>
`,
providers: [Stormpath]
})
export class AppComponent implements OnInit {
protected loginFormModel: LoginFormModel;
protected error: string;
private user$: Observable<Account | boolean>;
private loggedIn$: Observable<boolean>;
private _login: boolean;
private _register: boolean;
constructor(public stormpath: Stormpath) {
this.loginFormModel = {
login: '',
password: ''
};
}
ngOnInit(): void {
this._login = true;
this._register = false;
this.user$ = this.stormpath.user$;
this.loggedIn$ = this.user$.map(user => !!user);
}
showLogin(): void {
this._login = !(this._register = false);
}
showRegister(): void {
this._register = !(this._login = false);
}
login(): void {
this.error = null;
this.stormpath.login(this.loginFormModel)
.subscribe(null, (error: StormpathErrorResponse) => {
this.error = error.message;
});
}
logout(): void {
this.stormpath.logout();
}
}
NOTE: One problem with this approach is you'll need to copy all the referenced variables in the template into your component. Another option is to extend the existing Stormpath component and override its template
variable in @Component
.
To change the storage mechanism for authentication tokens from localStorage (the default), to cookies, change the class for the 'tokenStore' provider.
{
provide: 'tokenStore', useClass: CookieTokenStoreManager
}
Below is a list of direct links to each component. You can use the HTML defined in their template
variable as a starting point for your customizations.
<script src="node_modules/dist/umd/stormpath-sdk-angular/stormpath-sdk-angular.js"></script>
<script>
// everything is exported Stormpath namespace
</script>
All documentation is auto-generated from the source via typedoc and can be viewed here: https://docs.stormpath.com/angular/api
npm install
while current directory is this repoRun npm start
to start a development server on port 8000 with auto reload + tests.
Run npm test
to run tests once or npm run test:watch
to continually run tests.
If you want to use npm link
to use this module in another Angular project, follow the steps below:
npm run build:dist
.npm link
in this project's directory.npm link angular-stormpath
in the <test-project>
.rm -rf node_modules/angular-stormpath/node_modules
in <test-project>
.angular-stormpath
:npm install ng2-webstorage angular2-cookie --save
npm run release
For more information, see generator-angular-library. It was used to create this project.
Apache-2.0 © Stormpath
FAQs
Stormpath Components for Angular.
The npm package angular-stormpath receives a total of 23 weekly downloads. As such, angular-stormpath popularity was classified as not popular.
We found that angular-stormpath demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.