Here is some code I ended up with trying to get this to work and I started with https://github.com/oktadeveloper/okta-aspnet-mvc-example.git I ended up upgrading the dependencies which required some refactoring. I just want to know how this works basically
private async Task DoCodeRecievedWork(Microsoft.Owin.Security.Notifications.AuthorizationCodeReceivedNotification notification)
{
try
{
var tokenResponse = await _tokenClient.RequestAuthorizationCodeTokenAsync(notification.ProtocolMessage.Code, redirectUri);
if (tokenResponse.IsError)
{
throw new Exception(tokenResponse.Error);
}
UserInfoRequest request = new UserInfoRequest();
request.Address = authority + "/v1/userinfo";
request.Token = tokenResponse.AccessToken;
//calling this is magically enough to make it all work *shrug
var userInfoResponse = await _client.GetUserInfoAsync(request);
if (userInfoResponse.IsError)
{
throw new Exception("Exception calling GetUserInfoAsync :" + userInfoResponse.Error);
}
}
catch (Exception ex)
{
_logger.Error(ex.ToString());
notification.Response.Redirect("/?oktaerror=True");
}
}