private void UpdateAuthenticationManager()
{
// OAuth client info
OAuthClientInfo oauthInfo = new OAuthClientInfo
{
ClientId = AppClientId,
RedirectUri = new Uri(OAuthRedirectUrl)
};
// If a client secret has been included, add it
if (!string.IsNullOrEmpty(ClientSecret))
{
oauthInfo.ClientSecret = ClientSecret;
}
// Register the server information (and OAuth info) with the AuthenticationManager
ServerInfo portalServerInfo = new ServerInfo
{
ServerUri = new Uri(PortalUrl),
OAuthClientInfo = oauthInfo,
};
// Specify OAuthAuthorizationCode if a valid client secret has been specified (need a refresh token, e.g.)
if (!string.IsNullOrEmpty(ClientSecret))
{
portalServerInfo.TokenAuthenticationType = TokenAuthenticationType.OAuthAuthorizationCode;
}
else
{
// Otherwise, use OAuthImplicit
portalServerInfo.TokenAuthenticationType = TokenAuthenticationType.OAuthImplicit;
}
// Get a reference to the (singleton) AuthenticationManager for the app
AuthenticationManager thisAuthenticationManager = AuthenticationManager.Current;
// Register the server information
thisAuthenticationManager.RegisterServer(portalServerInfo);
// Assign the method that AuthenticationManager will call to challenge for secured resources
thisAuthenticationManager.ChallengeHandler = new ChallengeHandler(CreateCredentialAsync);
// Set the OAuth authorization handler to this class (Implements IOAuthAuthorize interface)
thisAuthenticationManager.OAuthAuthorizeHandler = this;
}