Demo
App: https://7jpsan.github.io/spotify-auth-demo/ Repo: https://github.com/7jpsan/spotify-auth-demo/
Spotify Auth - Angular 5
This is a simple library that handles the authentication workflow for an angular 5 application interacting with angular api in a JS only environment, no backend service is required!
Features (v2+):
- An auth library for spotify api v1 and angular 5
- A demo application that exemplifies the use.
Coming next:
- Handle token expiration / invalidity
- Handle session persistence
Difference of this fork
This is a fork/implementation of https://github.com/cyrilletuzi/angular-quickstart-lib which was forked from https://github.com/filipesilva/angular-quickstart-lib go ahead and read their work, it is awesome!
Gotchas
After a lot of time, using the @angular/router
and/or RouterModule
in a library is quite complicated... I have decided to remove it and expose the mechanisms to the consumer app.
Requirements
Make sure you have at least Node 6.9 and NPM 3.0 installed.
Install
npm install spotify-auth
Usage
-
Inherit the http Interceptor
spotify-auth.interceptor.ts
;; //Required, yes!; -
Listen for the
authService.authorizedStream
and route accordingly. When the login is complete, the stream will emit a true value, which means everything is ok (it hit theauthorized
url with the right stuff, you should now go to a route you have defined in your router module.app.component.ts
;;...constructorprivate infoSvc: InfoService,private tokenSvc: TokenService,private authService: AuthService,private router: RouterngOnInit: void... -
Create an
authorize/login
method that uses the module:login.component.ts
;;... -
app.module.ts
and/orapp-routing.module.ts
:;...;;;NgModule
That is it! The code should take care of the rest for you. Enjoy! There is a demo app here https://github.com/7jpsan/spotify-auth-demo. Ignore the one present in this repo. It was split, but never removed. Self TODO :)
If anything goes wrong, please raise an issue!