You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+308-1Lines changed: 308 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,8 @@ It provides support for seven passport based strategies.
26
26
8.[passport-apple](https://github.com/ananay/passport-apple) - Passport strategy for authenticating with Apple using the Apple OAuth 2.0 API. This module lets you authenticate using Apple in your Node.js applications.
27
27
9.[passport-facebook](https://github.com/jaredhanson/passport-facebook) - Passport strategy for authenticating with Facebook using the Facebook OAuth 2.0 API. This module lets you authenticate using Facebook in your Node.js applications.
28
28
10.[passport-cognito-oauth2](https://github.com/ebuychance/passport-cognito-oauth2) - Passport strategy for authenticating with Cognito using the Cognito OAuth 2.0 API. This module lets you authenticate using Cognito in your Node.js applications.
29
-
11. custom-passport-otp - Created a Custom Passport strategy for 2-Factor-Authentication using OTP (One Time Password).
29
+
11.[passport-SAML](https://github.com/node-saml/passport-saml) - Passport strategy for authenticating with SAML using the SAML 2.0 API. This module lets you authenticate using SAML in your Node.js applications
30
+
12. custom-passport-otp - Created a Custom Passport strategy for 2-Factor-Authentication using OTP (One Time Password).
30
31
31
32
You can use one or more strategies of the above in your application. For each of the strategy (only which you use), you just need to provide your own verifier function, making it easily configurable. Rest of the strategy implementation intricacies is handled by extension.
SAML (Security Assertion Markup Language) is an XML-based standard for exchanging authentication and authorization data between parties, in particular, between an identity provider (IdP) and a service provider (SP).
2602
+
2603
+
First, create a AuthUser model implementing the IAuthUser interface. You can implement the interface in the user model itself. See sample below.
2604
+
2605
+
```ts
2606
+
@model({
2607
+
name: 'users',
2608
+
})
2609
+
exportclassUserextendsEntityimplementsIAuthUser {
2610
+
@property({
2611
+
type: 'number',
2612
+
id: true,
2613
+
})
2614
+
id?:number;
2615
+
@property({
2616
+
type: 'string',
2617
+
required: true,
2618
+
name: 'first_name',
2619
+
})
2620
+
firstName:string;
2621
+
@property({
2622
+
type: 'string',
2623
+
name: 'last_name',
2624
+
})
2625
+
lastName:string;
2626
+
@property({
2627
+
type: 'string',
2628
+
name: 'middle_name',
2629
+
})
2630
+
middleName?:string;
2631
+
@property({
2632
+
type: 'string',
2633
+
required: true,
2634
+
})
2635
+
username:string;
2636
+
@property({
2637
+
type: 'string',
2638
+
})
2639
+
email?:string;
2640
+
// Auth provider - 'SAML'
2641
+
@property({
2642
+
type: 'string',
2643
+
required: true,
2644
+
name: 'auth_provider',
2645
+
})
2646
+
authProvider:string;
2647
+
// Id from external provider
2648
+
@property({
2649
+
type: 'string',
2650
+
name: 'auth_id',
2651
+
})
2652
+
authId?:string;
2653
+
@property({
2654
+
type: 'string',
2655
+
name: 'auth_token',
2656
+
})
2657
+
authToken?:string;
2658
+
@property({
2659
+
type: 'string',
2660
+
})
2661
+
password?:string;
2662
+
constructor(data?:Partial<User>) {
2663
+
super(data);
2664
+
}
2665
+
}
2666
+
```
2667
+
2668
+
Now bind this model to USER_MODEL key in application.ts
Create CRUD repository for the above model. Use loopback CLI.
2675
+
2676
+
```sh
2677
+
lb4 repository
2678
+
```
2679
+
2680
+
Add the verifier function for the strategy. You need to create a provider for the same. You can add your application specific business logic for client auth here. Here is a simple example.
throw new HttpErrors.Unauthorized(AuthErrorKeys.InvalidCredentials);
2864
+
}
2865
+
}
2866
+
```
2867
+
2868
+
Please note above that we are creating two new APIs for SAML. The first one is for UI clients to hit. We are authenticating client as well, then passing the details to the SAML. Then, the actual authentication is done by SAML authorization url, which redirects to the second API we created after success. The first API method body is empty as we do not need to handle its response. The SAML provider in this package will do the redirection for you automatically.
2869
+
2870
+
For accessing the authenticated AuthUser model reference, you can inject the CURRENT_USER provider, provided by the extension, which is populated by the auth action sequence above.
The `logoutVerify` function is used in the node-saml library as a part of the Passport SAML authentication process. This function is used to verify the authenticity of a SAML logout request.
2878
+
The logout process in SAML is used to end the user's session on the service provider, and the logoutVerify function is used to verify that the logout request is coming from a trusted IdP.
2879
+
The implementation of the logoutVerify function may vary depending on the specific requirements and the security constraints of the application. It is typically used to verify the signature on the logout request, to ensure that the request has not been tampered with, and to extract the user's identity information from the request.
2880
+
2881
+
```ts
2882
+
function logoutVerify(
2883
+
req:Request<AnyObject, AnyObject, AnyObject>,
2884
+
profile:Profile|null,
2885
+
done:VerifiedCallback,
2886
+
):void {
2887
+
// Check if a user is currently authenticated
2888
+
if (req.isAuthenticated()) {
2889
+
// Log the user out by removing their session data
// Call the "done" callback with an error to indicate that the user is not logged in
2895
+
done(newError('User is not currently logged in'));
2896
+
}
2897
+
}
2898
+
```
2899
+
2900
+
This function is called when a user logs out of the application.Once this function is implemented,it will be called when the user logs out of the application,allowing the application to perform any necessary tasks before ending the user's session.
2901
+
@param req - The request object.
2902
+
@param {Profile | null} profile - The user's profile, as returned by the provider.
2903
+
@param {VerifiedCallback} done - A callback to be called when the verificationis complete.
2904
+
2598
2905
### Https proxy support for keycloak and google auth
2599
2906
2600
2907
If a https proxy agent is needed for keycloak and google auth, just add an environment variable named `HTTPS_PROXY` or `https_proxy` with proxy url as value. It will add that proxy agent to the request.
0 commit comments