当前位置: 首页>>代码示例>>Java>>正文


Java Credentials类代码示例

本文整理汇总了Java中net.dean.jraw.http.oauth.Credentials的典型用法代码示例。如果您正苦于以下问题:Java Credentials类的具体用法?Java Credentials怎么用?Java Credentials使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Credentials类属于net.dean.jraw.http.oauth包,在下文中一共展示了Credentials类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: userlessAuthentication

import net.dean.jraw.http.oauth.Credentials; //导入依赖的package包/类
public static Completable userlessAuthentication(
        final RedditClient reddit,
        final Credentials credentials) {
    return Completable.create(new CompletableOnSubscribe() {
        @Override
        public void subscribe(CompletableEmitter e) throws Exception {
            try {
                OAuthData oAuthData = reddit.getOAuthHelper().easyAuth(credentials);
                reddit.authenticate(oAuthData);
                e.onComplete();
            } catch (Exception ex) {
                e.onError(ex);
            }
        }
    });
}
 
开发者ID:jorgegil96,项目名称:JRAW-Android-Sample,代码行数:17,代码来源:RedditService.java

示例2: userAuthentication

import net.dean.jraw.http.oauth.Credentials; //导入依赖的package包/类
public static Completable userAuthentication(
        final RedditClient reddit,
        final Credentials credentials,
        final String url) {
    return Completable.create(new CompletableOnSubscribe() {
        @Override
        public void subscribe(CompletableEmitter e) throws Exception {
            OAuthHelper oAuthHelper = reddit.getOAuthHelper();

            try {
                OAuthData oAuthData = oAuthHelper.onUserChallenge(url, credentials);
                reddit.authenticate(oAuthData);
                AuthenticationManager.get().onAuthenticated(oAuthData);
                e.onComplete();
            } catch (Exception ex) {
                e.onError(ex);
            }
        }
    });
}
 
开发者ID:jorgegil96,项目名称:JRAW-Android-Sample,代码行数:21,代码来源:RedditService.java

示例3: logout

import net.dean.jraw.http.oauth.Credentials; //导入依赖的package包/类
public static Completable logout(final Credentials credentials) {
    return Completable.create(new CompletableOnSubscribe() {
        @Override
        public void subscribe(CompletableEmitter e) throws Exception {
            try {
                AuthenticationManager.get().getRedditClient().getOAuthHelper()
                        .revokeAccessToken(credentials);
                AuthenticationManager.get().getRedditClient().getOAuthHelper()
                        .revokeRefreshToken(credentials);
                // Calling deauthenticate() isn't really necessary, since revokeAccessToken()
                // already calls it.
                // AuthenticationManager.get().getRedditClient().deauthenticate();

                // As of JRAW 9.0.0, revoking the access/refresh token does not update the
                // auth state to NONE (it instead remains as NEEDS_REFRESH), so to completely
                // restart the session to a blank state you should re-instantiate the
                // AuthenticationManager. See https://github.com/mattbdean/JRAW/issues/196

                // AuthenticationManager.get().init(...., ....); uncomment this line.
                e.onComplete();
            } catch (Exception ex) {
                e.onError(ex);
            }
        }
    });
}
 
开发者ID:jorgegil96,项目名称:JRAW-Android-Sample,代码行数:27,代码来源:RedditService.java

示例4: doUserlessAuth

import net.dean.jraw.http.oauth.Credentials; //导入依赖的package包/类
private void doUserlessAuth() {
    Credentials credentials = ((MyApplication) getApplication()).getUserlessAppCredentials();
    disposables.add(RedditService.userlessAuthentication(
                AuthenticationManager.get().getRedditClient(), credentials)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeWith(new DisposableCompletableObserver() {
                @Override
                public void onComplete() {
                    Toast.makeText(MainActivity.this, "Authentication complete!",
                            Toast.LENGTH_SHORT).show();
                }

                @Override
                public void onError(Throwable e) {
                    Toast.makeText(MainActivity.this, "Something went wrong",
                            Toast.LENGTH_SHORT).show();
                }
            })
    );
}
 
开发者ID:jorgegil96,项目名称:JRAW-Android-Sample,代码行数:22,代码来源:MainActivity.java

示例5: refreshToken

import net.dean.jraw.http.oauth.Credentials; //导入依赖的package包/类
private void refreshToken() {
    if (!AuthenticationManager.get().getRedditClient().hasActiveUserContext()) {
        Toast.makeText(MainActivity.this, "No need to refresh userless auth tokens",
                Toast.LENGTH_SHORT).show();
    } else {
        Credentials credentials = ((MyApplication) getApplicationContext())
                .getInstalledAppCredentials();
        disposables.add(RedditService.refreshToken(credentials)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new DisposableCompletableObserver() {
                    @Override
                    public void onComplete() {
                        Toast.makeText(MainActivity.this, "Token refreshed",
                                Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onError(Throwable e) {
                        Toast.makeText(MainActivity.this, "Something went wrong",
                                Toast.LENGTH_SHORT).show();
                    }
                })
        );
    }
}
 
开发者ID:jorgegil96,项目名称:JRAW-Android-Sample,代码行数:27,代码来源:MainActivity.java

示例6: run

import net.dean.jraw.http.oauth.Credentials; //导入依赖的package包/类
@Override
public void run() {
    Credentials creds = Credentials.userless(
            reddigramBot.config().clientId(),
            reddigramBot.config().clientSecret(),
            reddigramBot.deviceId()
    );
    OAuthData data;

    try {
        data = reddigramBot.client().getOAuthHelper().easyAuth(creds);
    } catch (OAuthException ex) {
        // Oh no! Complain to owner and shut down
        reddigramBot.log("Couldn't authenticate the bot! Shutting down...");
        ex.printStackTrace();
        reddigramBot.sendToOwner("Couldn't complete OAuth with Reddit (message=" + ex.getMessage() + ")");
        return;
    }

    reddigramBot.client().authenticate(data);
}
 
开发者ID:mkotb,项目名称:Reddigram,代码行数:22,代码来源:OAuthTask.java

示例7: refreshToken

import net.dean.jraw.http.oauth.Credentials; //导入依赖的package包/类
public static Completable refreshToken(final Credentials credentials) {
    return Completable.create(new CompletableOnSubscribe() {
        @Override
        public void subscribe(CompletableEmitter e) throws Exception {
            try {
                AuthenticationManager.get().refreshAccessToken(credentials);
                e.onComplete();
            } catch (Exception ex) {
                e.onError(ex);
            }
        }
    });
}
 
开发者ID:jorgegil96,项目名称:JRAW-Android-Sample,代码行数:14,代码来源:RedditService.java

示例8: onActivityResult

import net.dean.jraw.http.oauth.Credentials; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
        Credentials credentials = ((MyApplication) getApplication())
                .getInstalledAppCredentials();

        disposables.add(RedditService.userAuthentication(
                    AuthenticationManager.get().getRedditClient(),
                    credentials,
                    data.getStringExtra("RESULT_URL"))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new DisposableCompletableObserver() {
                    @Override
                    public void onComplete() {
                        String username = AuthenticationManager.get().getRedditClient()
                                .getAuthenticatedUser();
                        Toast.makeText(MainActivity.this, "Logged in as " + username,
                                Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onError(Throwable e) {
                        Toast.makeText(MainActivity.this, "Something went wrong",
                                Toast.LENGTH_SHORT).show();
                    }
                })
        );
    }
}
 
开发者ID:jorgegil96,项目名称:JRAW-Android-Sample,代码行数:31,代码来源:MainActivity.java

示例9: logout

import net.dean.jraw.http.oauth.Credentials; //导入依赖的package包/类
private void logout() {
    if (!AuthenticationManager.get().getRedditClient().hasActiveUserContext()) {
        Toast.makeText(MainActivity.this, "No need to logout of userless auth",
                Toast.LENGTH_SHORT).show();
    } else {
        Credentials credentials = ((MyApplication) getApplicationContext())
                .getInstalledAppCredentials();

        disposables.add(RedditService.logout(credentials)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new DisposableCompletableObserver() {
                    @Override
                    public void onComplete() {
                        Toast.makeText(MainActivity.this, "Deauthenticated!",
                                Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onError(Throwable e) {
                        Toast.makeText(MainActivity.this, "Something went wrong",
                                Toast.LENGTH_SHORT).show();
                    }
                })
        );
    }
}
 
开发者ID:jorgegil96,项目名称:JRAW-Android-Sample,代码行数:28,代码来源:MainActivity.java

示例10: getAuthorizationUrl

import net.dean.jraw.http.oauth.Credentials; //导入依赖的package包/类
private  URL getAuthorizationUrl() {
    OAuthHelper oAuthHelper = AuthenticationManager.get().getRedditClient().getOAuthHelper();
    Credentials credentials = ((MyApplication) getApplication()).getInstalledAppCredentials();
    String[] scopes = {"identity", "edit", "flair", "mysubreddits", "read", "vote",
            "submit", "subscribe", "history", "save"};
    return oAuthHelper.getAuthorizationUrl(credentials, true, true, scopes);
}
 
开发者ID:jorgegil96,项目名称:JRAW-Android-Sample,代码行数:8,代码来源:LoginActivity.java

示例11: ScraperBot

import net.dean.jraw.http.oauth.Credentials; //导入依赖的package包/类
public ScraperBot() throws OAuthException {
    UserAgent agent = UserAgent.of("script", "io.github.<username>", "v0.1", "<username>");
    client = new RedditClient(agent);

    Credentials cred = Credentials.script("<username>", "<password>", "<public key>", "<private key>");
    OAuthData data = client.getOAuthHelper().easyAuth(cred);

    client.authenticate(data);

    posts = new HashMap<>();
}
 
开发者ID:nikmanG,项目名称:DailyProgrammer,代码行数:12,代码来源:ScraperBot.java

示例12: getCredentials

import net.dean.jraw.http.oauth.Credentials; //导入依赖的package包/类
@Override
public Credentials getCredentials() {
    if (!this.preferences.uniqueUUID().exists()) {
        this.preferences.uniqueUUID().put(UUID.randomUUID().toString());
    }

    UUID uuid = UUID.fromString(this.preferences.uniqueUUID().get());

    // use the same uuid per install
    return Credentials.userlessApp(this.oauthClientId, uuid);
}
 
开发者ID:AlbinoDrought,项目名称:party-reader,代码行数:12,代码来源:UserlessCredentialFactory.java

示例13: init

import net.dean.jraw.http.oauth.Credentials; //导入依赖的package包/类
public void init() {
    log.info("got here");
    try {
        UserAgent myUserAgent = UserAgent.of("desktop", "com.flowchat", "v0.1", "dessalines");
        redditClient = new RedditClient(myUserAgent);
        Credentials credentials = Credentials.script(DataSources.PROPERTIES.getProperty("reddit_username"),
                DataSources.PROPERTIES.getProperty("reddit_password"),
                DataSources.PROPERTIES.getProperty("reddit_client_id"),
                DataSources.PROPERTIES.getProperty("reddit_client_secret"));
        OAuthData authData = redditClient.getOAuthHelper().easyAuth(credentials);
        redditClient.authenticate(authData);
    } catch (OAuthException e) {
        e.printStackTrace();
    }
}
 
开发者ID:dessalines,项目名称:flowchat,代码行数:16,代码来源:RedditImporter.java

示例14: getCredentials

import net.dean.jraw.http.oauth.Credentials; //导入依赖的package包/类
@Bean
public Credentials getCredentials() {
    return new Credentials(AuthenticationMethod.SCRIPT,
            environment.getRequiredProperty("reddit.username"),
            environment.getRequiredProperty("reddit.password"),
            environment.getRequiredProperty("reddit.clientId"),
            environment.getRequiredProperty("reddit.clientSecret"),
            null, //deviceId, not used by us
            environment.getRequiredProperty("reddit.redirectUrl"));
}
 
开发者ID:sgskinner,项目名称:StashThisBot,代码行数:11,代码来源:StashThisConfiguration.java

示例15: buildCredentials

import net.dean.jraw.http.oauth.Credentials; //导入依赖的package包/类
private Credentials buildCredentials(){
    String username = properties.getProperty("credentials.username");
    String password = properties.getProperty("credentials.password");
    String clientId = properties.getProperty("credentials.client.id");
    String clientSecret = properties.getProperty("credentials.client.secret");
    String redirectUrl = properties.getProperty("credentials.redirect.url");

    return Credentials.script(username, password, clientId, clientSecret, redirectUrl);
}
 
开发者ID:vitalijzad,项目名称:java-rss-for-reddit,代码行数:10,代码来源:RedditSubmitter.java


注:本文中的net.dean.jraw.http.oauth.Credentials类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。