forked from bojidaryovchev/nest-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented Facebook Login without the SDK. Here is the login flow:
You click the Facebook Login button and a request is send to the server to get the redirect_uri to the Facebook login page (the user is redirected when the redirect_uri is returned). Upon entering credentials and giving consent to the application, the user gets redirected back to the app with queryParams in the url containing a code which is then used to obtain an access_token from Facebook. This access_token is returned to the client and the client sends a request with it to the server to invoke the passport-facebook-token strategy and handle the user.
- Loading branch information
1 parent
979b4ba
commit efddd5c
Showing
12 changed files
with
159 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { FACEBOOK_CONFIG_TOKEN } from '../../server.constants'; | ||
import { facebookConfig } from './config/facebook-config'; | ||
|
||
export const authProviders = [ | ||
{ | ||
provide: FACEBOOK_CONFIG_TOKEN, | ||
useValue: facebookConfig | ||
} | ||
]; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { IFacebookConfig } from '../interfaces/facebook-config.interface'; | ||
|
||
export const facebookConfig: IFacebookConfig = { | ||
login_dialog_uri: 'https://www.facebook.com/v2.12/dialog/oauth', | ||
access_token_uri: 'https://graph.facebook.com/v2.12/oauth/access_token', | ||
client_id: '545785722443649', | ||
client_secret: 'a7b3b484ed5b0217b89824541eca1f4e', | ||
oauth_redirect_uri: 'http://localhost:4200/recipes', | ||
state: '{fbstate}' | ||
}; |
8 changes: 8 additions & 0 deletions
8
src/server/modules/auth/interfaces/facebook-config.interface.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export interface IFacebookConfig { | ||
login_dialog_uri: string; | ||
access_token_uri: string; | ||
client_id: string; | ||
client_secret: string; | ||
oauth_redirect_uri: string; | ||
state: string; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Component, Inject } from '@nestjs/common'; | ||
import { use } from 'passport'; | ||
|
||
import { FACEBOOK_CONFIG_TOKEN } from '../../../server.constants'; | ||
import { IFacebookConfig } from '../interfaces/facebook-config.interface'; | ||
|
||
const FacebookTokenStrategy = require('passport-facebook-token'); | ||
|
||
@Component() | ||
export class FacebookStrategy { | ||
constructor( | ||
@Inject(FACEBOOK_CONFIG_TOKEN) private readonly fbConfig: IFacebookConfig | ||
) { | ||
this.init(); | ||
} | ||
|
||
private init(): void { | ||
use('facebook', new FacebookTokenStrategy({ | ||
clientID: this.fbConfig.client_id, | ||
clientSecret: this.fbConfig.client_secret | ||
}, function(accessToken: string, refreshToken: string, profile: any, done: Function) { | ||
console.log(profile); | ||
})) | ||
} | ||
} |
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