ng-dynami-social-login
Version:
This is social login API for Angular 7.0.3 (Facebook, Google and Linkedin)
132 lines (96 loc) • 3.2 kB
Markdown
This is social login API for Angular 7.0.3 (Facebook, Google and Linkedin)
Big thanks to https://github.com/sabyasachibiswal/angular5-social-login . Since They do not support angular 7+ I have modified their source code and published it here to help others.
## Getting Started
### Install package via npm installer
```sh
npm install ng-dynami-social-login
```
###Import the module
In `app.module.ts`
```javascript
...
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { DynamiSocialLoginModule, AuthServiceConfig, GoogleLoginProvider } from 'ng-dynami-social-login';
export function getAuthServiceConfigs() {
let config = new AuthServiceConfig(
[
{
id: FacebookLoginProvider.PROVIDER_ID,
provider: new FacebookLoginProvider("XXXXXX")
},
{
id: GoogleLoginProvider.PROVIDER_ID,
provider: new GoogleLoginProvider("XXXxXXXX.apps.googleusercontent.com")
}
,
{
id: LinkedinLoginProvider.PROVIDER_ID,
provider: new LinkedinLoginProvider("XXXXXXXxXX")
},
]
);
return config;
}
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
DynamiSocialLoginModule
],
providers: [{
provide: AuthServiceConfig,
useFactory: getAuthServiceConfigs
}],
bootstrap: [AppComponent]
})
export class AppModule { }
```
In `login.component.html`
```html
<h1>
Sign in
</h1>
<button (click)="socialSignIn('facebook')">Sign in with Facebook</button>
<button (click)="socialSignIn('google')">Signin in with Google</button>
```
In `login.componentng g c logo.ts`
```javascript
...
import { Component, OnInit } from '@angular/core';
import { AuthService, FacebookLoginProvider, GoogleLoginProvider, LinkedinLoginProvider } from 'ng-dynami-social-login';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
constructor(private socialAuthService: AuthService) { }
ngOnInit() {
}
public socialSignIn(socialPlatform : string) {
let socialPlatformProvider;
if(socialPlatform == "facebook"){
socialPlatformProvider = FacebookLoginProvider.PROVIDER_ID;
}else if(socialPlatform == "google"){
socialPlatformProvider = GoogleLoginProvider.PROVIDER_ID;
} else if (socialPlatform == "linkedin") {
socialPlatformProvider = LinkedinLoginProvider.PROVIDER_ID;
}
this.socialAuthService.signIn(socialPlatformProvider).then(
(userData) => {
console.log(userData);
}
);
}
}
```
### Facebook App Id :
You need to create your own facebook app by going to [Facebook Developers](https://developers.facebook.com/) page.
Add `Facebook login` under products and configure `Valid OAuth redirect URIs`.
### Google Client Id :
Follow this official documentation on how to [
Create a Google API Console project and client ID](https://developers.google.com/identity/sign-in/web/devconsole-project).