Hi,
I am having a little bit of trouble figuring out OAuth authentication.
This is my current auth provider setup:
Plugins.Add(new AuthFeature(() => new AuthUserSession(),
new IAuthProvider[] {
new JwtAuthProvider(AppSettings) { AuthKeyBase64 = "cGFydHkgdGltZQ==", RequireSecureConnection=false },
new CredentialsAuthProvider(AppSettings),
new FacebookAuthProvider(AppSettings) {
RedirectUrl = "http://localhost:4200/pages/auth/register",
CallbackUrl = "http://localhost:5100/auth/facebook",
AppId = "123",
AppSecret = "123",
Fields = new string[] { "id", "email", "first_name", "last_name" },
Permissions = new string[] {"email"}
},
}));
When I hit http://localhost:5100/auth/facebook
the first time I approve permissions then it re-directs me back to site. I can see in database a user has been created. The page I get returned to is http://localhost:4200/pages/auth/register?s=1#_=_
and I can see ss-id
, ss-opt
and ss-pid
cookies are created on the application screen of chrome dev tools.
This is where I am getting confused. My current way to handle auth on frontend is to create a local object that stores the JWT token and then reference this when making requests. If I get an unauthorized error I delete the object and direct user to login page. I plan to use the role meta data in the JWT to customize the front end options.
How does this fit in with the OAuth cookies? From reading the documentation it seems like I have to now convert the session cookies into a token but I am struggling to figure that out.
I dont seem to be able to access the cookies from javascript. When I console.log(document.cookie)
the ss-id and ss-pid are not in the returned string but I can see them in dev tools.
I assume I need to do something along the lines of this in front end:
var client = new JsonServiceClient("http://localhost:5100");
var ssid : Cookie = {
name: "ss-id",
path: "/",
value: this.cookieService.get('ss-id')
}
var sspid : Cookie = {
name: "ss-pid",
path: "/",
value: this.cookieService.get('ss-pid')
}
client.cookies[0] = ssid;
client.cookies[1] = sspid;
var tokenResponse = await client.post(new ConvertSessionToToken());
And then I get the token? I can’t find any example of this so I feel like I am fumbling in the dark and I am unable to read the cookies generated by facebook auth so I am not sure if I am going in right direction or not.
What should I be doing after user is re-directed back from facebook to generate a token?