How to implement Salesforce JWT OAuth 2.0 bearer flow in React JS - reactjs

I am working on a react app project that needs to be integrated with Salesforce, for that I found this information where I explain that I need to implement "Salesforce JWT OAuth 2.0 bearer flow":
I also found information to complete this procedure by creating a private key and self-signed digital certificate
After that, I found the panva/jose library. Based on this information and following the steps above, I am trying to implement this feature in React JS app.
After some testing, I got the signed JWT using importPKCS8(serverKey, 'RS256'), but even when getting a token, I checked JWT.io and got "Invalid Signature". What could be the cause of this?
I also found similar questions answered by Filip Skokan, then, Filip or someone else with experience in implementing this kind of future could explain step by step the correct way to implement it.
Thanks in advance.

Related

React and MSGraph - send email

I'm having a hard time understanding how to send an email in react using msgraph. I have authentication working through MSal and can show the user profile. I have read the documentation and it feels like I'm missing many steps. Does anyone know of a sample project that authenticates and sends a test email? Ultimately I would like to create a reusable function that takes in the TO, Subject, Body.
Thank you for reaching out.
Refer to the module here.
This module will introduce you to working with the Microsoft Graph in creating a React single-page application to access data in Office 365.
Thanks.

oAuth 2 implementation in react js

I need a little guidance. I am trying to implement oAuth2 authentication in my React JS application. Backend is in service now. In react on login button click, service now popup will open to authenticate user and will provide access token at redirect uri.
I am having client id, client secret, access token uri, authorization uri, redirect uri.
But couldn't find any specific library for react js that gives oauth2 implementation. Please give me pointers so I can use any existing/implement oauth2 authentication for my Login page(using react).
I was trying to use ClientOAuth2, but I am not sure if this is correct to use with react js. Also, I am getting CORS error on using this library on my localhost.
Please share how to implement it properly.
I have a couple of tutorials you may find useful, which use the oidc-client library.
The design patterns used are technology neutral and can be implemented in any JavaScript tech stack.
TUTORIAL 1 : PLAIN TYPESCRIPT
This focuses on the basics of Authorization Code Flow (PKCE) and a productive developer setup:
Blog post
Code Sample
FINAL TUTORIAL: REACTJS
This focuses on some more advanced aspects, and includes an update to ReactJS:
Blog post
Code sample
I have used react-oauth2-auth-code-flow nom package to implement AUth2 flow in my react js application. The napm package has samples to help your implementation. Check this https://www.npmjs.com/package/react-oauth2-auth-code-flow

How to develop Remember Me Functionality with Angular JS + JWT Authentication using Spring Security 4 + Spring Rest API

I want to develop "Remember ME" functionality with Angular JS + JWT Authentication Using Spring Security 4 + Spring Rest API + Hibernate + Maven + Tomcat.
Because of some code review and business need, I am forced to use JWT method for user authentication and authorization with above mentioned Spring feature,
I searched on Internet for sample projects and application, But I couldnt find any solution?
Most of them doesn't serve my purpose or way complex to understand.
I would like to get a sample project for reference. Or an IDEA to complete this application. I am stuck with it.
Any one please help me.
Clarification:
My Login page should have "Remember Me" check-box, I have decided to use Spring Security remember me feature. But later when using Angular JS in client side, decided I should not use Spring Form tags that provides REMEMBER ME functionality.
And now I am unable to find example in Internet for this. So Please can any one help in creating an sample application.
It would be great if any one could help me with a sample application with good coding standard or some URL of sample codes
This could serve many people who are searching for a good Sample code to do this and enhance upon it.
Requesting help. I am stuck and have very less time to research things.
This is exactly what we did on this project:
https://github.com/RedFroggy/angular-spring-hmac
The stack is: AngularJS, Spring MVC, Spring Security, Spring Boot and a jwt authentication.

OpenId auth with AngularJS and MVC, with token cookie

I'm more looking for comfirmation of whether I'm doing this right or wrong. This is the scenario:
I'm hosting an AngularJS app in an ASP.NET MVC application. Using the MVC part I communicate with IdentityServer to log in, and once I do this I take the access_token from OWIN's OpenIdConnect validation notification and create a Cookie with it's value, which I then get in AngularJS with the $cookieStore object to use for my requests.
Admittedly, security is by far my weakest link, so my question is whether the above scenario is safe or am I violating some sort of security rule that would allow someone to find a hole in security?
Your question is kind of hard to answer, since we can't confirm what you are going to do in the future. Generally you are on the right path, but security is hard, so you should know when to let others do it.
IdentityServer v3 is a great start though.
Take a look at the samples, specifically the JavaScriptImplicitClient from here:
https://github.com/thinktecture/Thinktecture.IdentityServer.v3.Samples/tree/26293649324783cd5c6bbfe0dbb9e83c6df826fc/source/Clients
A nice article on Angular and WebAPI here as well:
http://www.codeproject.com/Articles/784106/AngularJS-Token-Authentication-using-ASP-NET-Web-A
Have fun!

Angularjs and SSO (SAML2)

I came across with this AngularJs thing, and I thing it is awesome, really solves many problems I confronted while working on my last WebApp with just a few lines of code.
Now, what I didn't find or was looking in bad places is the protection of AngularJs app with SSO (simpleSAMLphp Identity provider). How to deal with this?
What I am going to build will use Pyramid framework as a backend REST API, and AngularJs (I wish) for the frontend. But how to protect the app from unauthorized access, skipping the sso login. Any implementation example or lessons working on similar case would help (may be with php, ruby backends and SSO etc)
I doesn't seem like pyramid has any direct support for SAML authetication. I suggest using a third party application for SAML. For example Shibboleth. The SAML communication is done on the server side so Angular wont need any integration.
Google like 'Authentication in angular JS application' you can get lot to protect your angular app. To protect your REST API use Oauth whether its a php or ruby application.

Resources