Next-Auth v4.0 adapter for Sanity.io - adapter

I have tried to modify the existing adapter # https://www.sanity.io/plugins/next-auth-sanity to be compatible with Next-Auth V4 to no avail.
As I have read that Next-Auth V4 introduces some breaking changes to all existing adapters.
Has anyone integrated Next-Auth with Sanity.io for the EmailProvider option successfully with a custom adapter?
This is a piece of code (from the current next-auth-sanity library) which I believe is having some issues with next-Auth V4.
import { Profile, Session } from 'next-auth';
import { Adapter } from 'next-auth/adapters';
import { User } from 'next-auth';
import { SanityClient } from '#sanity/client';
export default function SanityAdapter(SanityClient, options = {never, User & {
id: string;
}, Profile, Session}) {
return {
}
}
The adapter documentation from next-auth is quite basic # Next-Auth Adapter documentation

Related

How to configure Quarkus to point to a non default name Neo4J DB?

Default configuration point to bolt://localhost:7687 and thus Neo4J DB but using entreprise edition you can create your own. Let's call it MyInstance
How to configure the uri to point to MyInstance using the plugin ?
The driver connects to a Neo4j server. You can then specify the database to use at the session level, for eg :
// imports
import org.neo4j.driver.Driver;
import org.neo4j.driver.GraphDatabase;
import org.neo4j.driver.Session;
import org.neo4j.driver.SessionConfig;
// ... other code
try (Session session = driver.session(SessionConfig.forDatabase("movies"))) {
session.writeTransaction((tx) -> {
tx.run("CREATE (n:Movie {name: $name})", Map.of("name", "The Matrix"));
return null;
});
}

How do i solve '"Reference to type 'BaseControlContext" claim.....' for AspNet.Security.OpenIdConnect.Server

I am facing weird issue.
I am reading and creating OpenID Connect server with ASOS this article ASOS - AspNet.Security.OpenIdConnect.Server.
I simply created new sample solution and added new subclass AuthorizationProvider class of OpenIdConnectServerProvider and override the virtual method i.e. ExtractAuthorizationRequest
AuthorizationProvider.cs
public class AuthorizationProvider : OpenIdConnectServerProvider
{
public override Task ExtractAuthorizationRequest(ExtractAuthorizationRequestContext context)
{
// If a request_id parameter can be found in the authorization request,
// restore the complete authorization request stored in the user session.
if (!string.IsNullOrEmpty(context.Request.RequestId))
{
var payload = context.HttpContext.Session.Get(context.Request.RequestId);
if (payload == null)
{
context.Reject(
error: OpenIdConnectConstants.Errors.InvalidRequest,
description: "Invalid request: timeout expired.");
return Task.FromResult(0);
}
// Restore the authorization request parameters from the serialized payload.
using (var reader = new BsonReader(new MemoryStream(payload)))
{
foreach (var parameter in JObject.Load(reader))
{
// Avoid overriding the current request parameters.
if (context.Request.HasParameter(parameter.Key))
{
continue;
}
context.Request.SetParameter(parameter.Key, parameter.Value);
}
}
}
return Task.FromResult(0);
}
}
Issue:
As soon as i add Microsoft.AspNetCore.Identity (2.0.0) NuGet package to my project, context.Reject start giving the following error
"Reference to type 'BaseControlContext" claim it is defined in
Microsoft.AspNetCore.Authentication, but it could not be found.
But as soon as I remove Microsoft.AspNetCore.Identity NuGet dependency, the error goes away and all looks fine.
Note:
I am using VS 2017.
I am using dotnetcore 2.0 SDK.
I created solution using .Net Core 2.0.
Massive changes have been introduced in ASP.NET Core 2.0's authentication stack. The changes are so important that all the authentication middleware written for ASP.NET Core 1.x are not compatible (which includes all the aspnet-contrib projects).
You can read https://github.com/aspnet/Announcements/issues/262 for more information.
The good news is that we have an ASP.NET Core 2.0 RTM-compatible version of ASOS. You can find the 2.0.0-preview1-* bits on the aspnet-contrib MyGet feed (https://www.myget.org/F/aspnet-contrib/api/v3/index.json).

Worklight Java adapter invoke another adapter get I/O issue

I have a issue when I try to call adapter (HTTP/MYSQL) from a Java adapter.
When I am using Postmen test it (added Authorization on the header)
It's always get a IO issue:
[I O: Invalid token on line 1, column 14].
First, I guess it should be OAuth issue, I add #OAuthSecurity(enabled=false) at the class but not work.
Would you please help me find out where the problem is.
Code snippet:
DataAccessService service = WorklightBundles.getInstance()
.getDataAccessService();
ProcedureQName name = new ProcedureQName("mysqlAdapter",
"getMysqlAdapters");
String para = ""; // String para = "['a','b','c']";
InvocationResult mysql= service.invokeProcedure(name, para);
JSONObject jsMysql = mysql.toJSON();
//String rst = jsMysql.get("key").toString();
PS following code snippet is working when I test it on Postman:
HttpUriRequest request = api.getAdaptersAPI()
.createJavascriptAdapterRequest("mysqlAdapter", "getMysqlAdapters");
try {
HttpResponse response = api.getAdaptersAPI().executeAdapterRequest(request);
JSONObject jsonObj =api.getAdaptersAPI().getResponseAsJSON(response);
return jsonObj.toString();
}
catch (MFPServerOAuthException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
return "error";
I am confused...
You use the tag "worklight", but the Product Worklight 4.x-6.2 does not have Java adapters support. There is JavaScript adapters support and the ability for a JavaScript adapter to call Java code on the server. There is also the ability to call a JavaScript adapter from Java code - but not do be confused as a Java adapter.
Java adapters exists only starting MobileFirst Platform Foundation 7.0 (formerly called "Worklight", tag is "mobilefirst"). I mention this because you've mentioned OAuth support, which was introduced alongside Java adapters in MobileFirst Platform Foundation 7.0. But this has got nothing to do with any of your code snippets. a Java adapter looks nothing like that.
So,
If you are using Worklight, you cannot use any of that OAuth stuff.
If you are using MobileFirst, you shouldn't call your adapters this way at all. Please review the Java adapters tutorial and first create a proper Java adapter: https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-0/server-side-development/adapter-framework-overview/
Also note that at this time it is not easily possible to call a Java adapter from a JavaScript adapter (the opposite way of your request, if it is to be understood correctly).

Shiro or Spring Security with Ninja framework or Spark

can I use Spring Security or Shiro Security with Ninja Framework or Spark Framework? I can't find any example to integrate this security frames with web frames. there is not any information in the ninja web site about user auth and web app security.
This question is quite old, but I am unable to find any example of integrating Apache Shiro with Ninja Framework, so here are my findings about this.
Ninja Framework requires an instance of AbstractModule, it shows me an error when you try something like the configuration that is recommended here:
package conf;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import org.apache.shiro.config.Ini;
import org.apache.shiro.realm.text.IniRealm;
import org.apache.shiro.guice.ShiroModule;
class Module extends ShiroModule {
protected void configureShiro() {
try {
bindRealm().toConstructor(IniRealm.class.getConstructor(Ini.class));
} catch (NoSuchMethodException e) {
addError(e);
}
}
#Provides
Ini loadShiroIni() {
return Ini.fromResourcePath("classpath:shiro.ini");
}
}
However checking the source code of ShiroModule class I noticed that it extends PrivateModule so this should work, at least I get no compilation errors:
package conf;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import org.apache.shiro.config.Ini;
import org.apache.shiro.realm.text.IniRealm;
import org.apache.shiro.guice.ShiroModule;
public class Module extends AbstractModule
{
#Override
protected void configure()
{
install(new ShiroModule()
{
#Override
protected void configureShiro()
{
//shiro recomended configuration
try {
bindRealm().toConstructor(IniRealm.class.getConstructor(Ini.class));
} catch (NoSuchMethodException e) {
addError(e);
}
}
#Provides
Ini loadShiroIni()
{
return Ini.fromResourcePath("classpath:shiro.ini");
}
});
}
}
Spark has the notion of filters. http://sparkjava.com/documentation.html#filters therefore you can add the Shiro or Spring Security filter. That said, it isn't as simple as dropping in a filter for either of these security frameworks. But in theory...
if you want to secure web restful api, suggest use the sureness - https://github.com/tomsun28/sureness
It is no specific framework dependency(support springboot, quarkus, javalin, ktor and more).
The essence of sureness is to intercept all rest requests for authenticating and Authorizing.
The interceptor can be a filter or a spring interceptor, it intercepts all request to check them.
What you need to know is that sureness is a project created by us, welcome to use.

Upload Youtube using Proxy, per connection and not system wide

I have a Java code using youtube-api to upload videos. Until now I was using the system configuration to set the proxy (http and https) and everything is working fine that way. But now I have a new requirement regarding the way we use proxy on the server. As we have other services running on the very same server, they asked me to not configure the proxy using system wide approach, because this affect all the services using JVM.
System.setProperty("http.proxyHost", httpProxyHost);
System.setProperty("http.proxyPort", httpProxyPort);
and
System.setProperty("https.proxyHost", httpsProxyHost);
System.setProperty("https.proxyPort", httpsProxyPort);
I have spent the last couple days researching that on the Internet and didn't find anything useful. I found a explanation on the C# API what seems to be setting the proxy to the connection and I didn't find a way to implement this same approach on Java.
I want to do something like this:
service = new YouTubeService(APPLICATION_NAME, DEVELOPER_KEY);
service.setUserCredentials(userName, password);
uploader = new ResumableGDataFileUploader.Builder(
service, new URL(RESUMABLE_UPLOAD_URL), ms, newVideoEntry)
.title(videoTitle)
.trackProgress(listener, PROGRESS_UPDATE_INTERVAL)
.chunkSize(DEFAULT_CHUNK_SIZE).build();
// fictional code to show what I want to do
uploader.setProxyHttp(httpProxyHost, httpProxyPort);
uploader.setProxyHttps(httpsProxyHost, httpsProxyPort);
uploader.start();
This is very similar to what Java already allow us to do. See this http://docs.oracle.com/javase/6/docs/technotes/guides/net/proxies.html
I just resolved with the following code. Adapt the method setPersonalUrlConnectionFactory to set your proxy and call it passing as argument your uploader.
package com.google.gdata.client.uploader;
import com.google.gdata.client.media.ResumableGDataFileUploader;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
public class PersonalUrlConnectionInjector {
public static void setPersonalUrlConnectionFactory(ResumableGDataFileUploader uploader) {
try {
java.lang.reflect.Field field = uploader.getClass().getSuperclass().getDeclaredField("urlConnectionFactory");
field.setAccessible(true);
java.lang.reflect.Field modifiersField = java.lang.reflect.Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~java.lang.reflect.Modifier.FINAL);
field.set(uploader, new UrlConnectionFactory() {
#Override
public HttpURLConnection create(URL url) throws IOException {
return new sun.net.www.protocol.http.HttpURLConnection(url, MY_PROXY);
}
});
} catch (Exception e) {
/* DO LOG */
}
}
}

Resources