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


Java OAuth20Credentials类代码示例

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


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

示例1: setUp

import org.pac4j.oauth.credentials.OAuth20Credentials; //导入依赖的package包/类
@Before
public void setUp() {
    this.fbClient = new FacebookClient();
    final Clients clients = new Clients(CALLBACK_URL, fbClient);
    this.handler = new ClientAuthenticationHandler("", mock(ServicesManager.class), null, clients);
    this.handler.setTypedIdUsed(true);

    final Credentials credentials = new OAuth20Credentials(null, fbClient.getName());
    this.clientCredential = new ClientCredential(credentials);
    ExternalContextHolder.setExternalContext(mock(ServletExternalContext.class));
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:12,代码来源:ClientAuthenticationHandlerTests.java

示例2: retrieveAccessToken

import org.pac4j.oauth.credentials.OAuth20Credentials; //导入依赖的package包/类
@Override
protected CompletableFuture<Void> retrieveAccessToken(OAuthCredentials credentials) {
    final OAuth20Credentials oAuth20Credentials = (OAuth20Credentials) credentials;
    // no request token saved in context and no token (OAuth v2.0)
    final String code = oAuth20Credentials.getCode();
    logger.debug("code: {}", code);
    final CompletableFuture<OAuth2AccessToken> accessTokenFuture = new CompletableFuture<>();

    this.configuration.getService().getAccessTokenAsync(code, ScribeCallbackAdapter.toScribeOAuthRequestCallback(accessTokenFuture));

    return accessTokenFuture.thenAccept(accessToken -> {
        logger.debug("accessToken: {}", accessToken);
        oAuth20Credentials.setAccessToken(accessToken);
    });
}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:16,代码来源:AsyncOAuth20Authenticator.java

示例3: getOAuthCredentials

import org.pac4j.oauth.credentials.OAuth20Credentials; //导入依赖的package包/类
@Override
protected OAuthCredentials getOAuthCredentials(final WebContext context) throws HttpAction {
    final String codeParameter = context.getRequestParameter(OAUTH_CODE);
    if (codeParameter != null) {
        final String code = OAuthEncoder.decode(codeParameter);
        logger.debug("code: {}", code);
        return new OAuth20Credentials(code, getName());
    } else {
        final String message = "No credential found";
        throw new OAuthCredentialsException(message);
    }
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:13,代码来源:BaseOAuth20Client.java

示例4: getAccessToken

import org.pac4j.oauth.credentials.OAuth20Credentials; //导入依赖的package包/类
@Override
protected OAuth2AccessToken getAccessToken(final OAuthCredentials credentials) throws HttpAction {
    OAuth20Credentials oAuth20Credentials = (OAuth20Credentials) credentials;
    // no request token saved in context and no token (OAuth v2.0)
    final String code = oAuth20Credentials.getCode();
    logger.debug("code: {}", code);
    final OAuth2AccessToken accessToken = this.service.getAccessToken(code);
    logger.debug("accessToken: {}", accessToken);
    return accessToken;
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:11,代码来源:BaseOAuth20Client.java

示例5: testOk

import org.pac4j.oauth.credentials.OAuth20Credentials; //导入依赖的package包/类
@Test
public void testOk() throws HttpAction {
    final OAuth20Credentials oauthCredential = (OAuth20Credentials) getClient()
            .getCredentials(MockWebContext.create().addRequestParameter(BaseOAuth20Client.OAUTH_CODE, CODE));
    assertNotNull(oauthCredential);
    assertEquals(CODE, oauthCredential.getCode());
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:8,代码来源:BaseOAuth20ClientTests.java

示例6: verifyFinishAuthentication

import org.pac4j.oauth.credentials.OAuth20Credentials; //导入依赖的package包/类
@Test
public void verifyFinishAuthentication() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.setParameter(Clients.DEFAULT_CLIENT_NAME_PARAMETER, "FacebookClient");

    final MockHttpSession mockSession = new MockHttpSession();
    mockSession.setAttribute(ThemeChangeInterceptor.DEFAULT_PARAM_NAME, MY_THEME);
    mockSession.setAttribute(LocaleChangeInterceptor.DEFAULT_PARAM_NAME, MY_LOCALE);
    mockSession.setAttribute(CasProtocolConstants.PARAMETER_METHOD, MY_METHOD);
    final Service service = CoreAuthenticationTestUtils.getService(MY_SERVICE);
    mockSession.setAttribute(CasProtocolConstants.PARAMETER_SERVICE, service);
    mockRequest.setSession(mockSession);

    final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class);
    when(servletExternalContext.getNativeRequest()).thenReturn(mockRequest);
    when(servletExternalContext.getNativeResponse()).thenReturn(new MockHttpServletResponse());

    final MockRequestContext mockRequestContext = new MockRequestContext();
    mockRequestContext.setExternalContext(servletExternalContext);

    final FacebookClient facebookClient = new FacebookClient() {
        @Override
        protected OAuth20Credentials retrieveCredentials(final WebContext context) throws HttpAction {
            return new OAuth20Credentials("fakeVerifier", FacebookClient.class.getSimpleName());
        }
    };
    facebookClient.setName(FacebookClient.class.getSimpleName());
    final Clients clients = new Clients(MY_LOGIN_URL, facebookClient);
    final TicketGrantingTicket tgt = new TicketGrantingTicketImpl(TGT_ID, mock(Authentication.class), mock(ExpirationPolicy.class));
    final CentralAuthenticationService casImpl = mock(CentralAuthenticationService.class);
    when(casImpl.createTicketGrantingTicket(any())).thenReturn(tgt);

    final AuthenticationTransactionManager transManager = mock(AuthenticationTransactionManager.class);
    final AuthenticationManager authNManager = mock(AuthenticationManager.class);
    when(authNManager.authenticate(any(AuthenticationTransaction.class))).thenReturn(CoreAuthenticationTestUtils.getAuthentication());

    when(transManager.getAuthenticationManager()).thenReturn(authNManager);
    when(transManager.handle(any(AuthenticationTransaction.class), any(AuthenticationResultBuilder.class))).thenReturn(transManager);

    final AuthenticationSystemSupport support = mock(AuthenticationSystemSupport.class);
    when(support.getAuthenticationTransactionManager()).thenReturn(transManager);

    final DelegatedClientAuthenticationAction action = new DelegatedClientAuthenticationAction(clients, support, casImpl,
            "theme", "locale", false);

    final Event event = action.execute(mockRequestContext);
    assertEquals("success", event.getId());
    assertEquals(MY_THEME, mockRequest.getAttribute(ThemeChangeInterceptor.DEFAULT_PARAM_NAME));
    assertEquals(MY_LOCALE, mockRequest.getAttribute(LocaleChangeInterceptor.DEFAULT_PARAM_NAME));
    assertEquals(MY_METHOD, mockRequest.getAttribute(CasProtocolConstants.PARAMETER_METHOD));
    assertEquals(MY_SERVICE, mockRequest.getAttribute(CasProtocolConstants.PARAMETER_SERVICE));
    final MutableAttributeMap flowScope = mockRequestContext.getFlowScope();
    final MutableAttributeMap requestScope = mockRequestContext.getRequestScope();
    assertEquals(service, flowScope.get(CasProtocolConstants.PARAMETER_SERVICE));
    assertEquals(TGT_ID, flowScope.get(TGT_NAME));
    assertEquals(TGT_ID, requestScope.get(TGT_NAME));
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:58,代码来源:DelegatedClientAuthenticationActionTests.java

示例7: getAccessToken

import org.pac4j.oauth.credentials.OAuth20Credentials; //导入依赖的package包/类
@Override
protected OAuth2AccessToken getAccessToken(OAuth20Credentials credentials) throws HttpAction {
    return credentials.getAccessToken();
}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:5,代码来源:AsyncOAuth20ProfileCreator.java


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