改进隐式OAuth 2.0身份验证

问题描述 投票:0回答:1

我正在开发一个简单的StackOverflow客户端。正如文档所说here我必须使用带有重定向url的隐式OAuth流。我打开CustomTabs并传递此链接https://stackoverflow.com/oauth。在应用程序中,有几个屏幕,其中的操作需要进行身份验证才能进行身份验证。我的问题是如何在每个屏幕上正确处理403错误,所以当我打开CustomTabs时,它会在收到未授权的响应时重定向到同一个屏幕。

提前致谢。

android oauth-2.0 retrofit okhttp
1个回答
0
投票

在In Retrofit BaseService Class中添加此项

私有静态类TokenInterceptor实现Interceptor {

    private TokenInterceptor() {

    }

    @Override
    public Response intercept(Chain chain) throws IOException {

        Request initialRequest = chain.request();

        initialRequest = initialRequest.newBuilder()
                .addHeader("Content-Type", "application/json")
                .build();

        Response response = chain.proceed(initialRequest);

        return response;
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.