Search in sources :

Example 1 with SyncWebAuthClient

use of com.okta.oidc.clients.web.SyncWebAuthClient in project okta-oidc-android by okta.

the class SyncSessionClientImplTest method setUp.

@Before
public void setUp() throws Exception {
    mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
    mEndPoint = new MockEndPoint();
    String url = mEndPoint.getUrl();
    mConfig = TestValues.getConfigWithUrl(url);
    mGson = new Gson();
    OktaStorage storage = new SharedPreferenceStorage(mContext);
    mProviderConfig = TestValues.getProviderConfiguration(url);
    mTokenResponse = TokenResponse.RESTORE.restore(TOKEN_RESPONSE);
    mClientFactory = new HttpClientFactory();
    mClientFactory.setClientType(mClientType);
    mHttpClient = mClientFactory.build();
    SyncWebAuthClient mSyncWebAuth = new Okta.SyncWebAuthBuilder().withConfig(mConfig).withOktaHttpClient(mHttpClient).withContext(mContext).withStorage(storage).withEncryptionManager(new EncryptionManagerStub()).create();
    mSyncSessionClientImpl = (SyncSessionClientImpl) mSyncWebAuth.getSessionClient();
    mOktaState = mSyncSessionClientImpl.getOktaState();
    mOktaState.save(mProviderConfig);
}
Also used : OktaStorage(com.okta.oidc.storage.OktaStorage) SharedPreferenceStorage(com.okta.oidc.storage.SharedPreferenceStorage) MockEndPoint(com.okta.oidc.util.MockEndPoint) Gson(com.google.gson.Gson) EncryptionManagerStub(com.okta.oidc.util.EncryptionManagerStub) SyncWebAuthClient(com.okta.oidc.clients.web.SyncWebAuthClient) HttpClientFactory(com.okta.oidc.util.HttpClientFactory) Before(org.junit.Before)

Example 2 with SyncWebAuthClient

use of com.okta.oidc.clients.web.SyncWebAuthClient in project okta-oidc-android by okta.

the class SyncSessionClientImplTest method userProfileRequestOAuth2.

@Test
public void userProfileRequestOAuth2() throws AuthorizationException, OktaRepository.EncryptionException {
    mExpectedEx.expect(AuthorizationException.class);
    // create sessionclient from oauth2 resource
    OIDCConfig oauth2Config = TestValues.getConfigWithUrl(mEndPoint.getUrl() + "/oauth2/default/");
    SyncWebAuthClient syncWebAuthClient = new Okta.SyncWebAuthBuilder().withConfig(oauth2Config).withOktaHttpClient(mHttpClient).withContext(mContext).withStorage(new SharedPreferenceStorage(mContext, "oauth2prefs")).withEncryptionManager(new EncryptionManagerStub()).create();
    SyncSessionClientImpl sessionClient = (SyncSessionClientImpl) syncWebAuthClient.getSessionClient();
    AuthorizedRequest request = sessionClient.userProfileRequest(mOktaState.getProviderConfiguration(), mOktaState.getTokenResponse());
    request.executeRequest(mHttpClient);
}
Also used : SharedPreferenceStorage(com.okta.oidc.storage.SharedPreferenceStorage) AuthorizedRequest(com.okta.oidc.net.request.AuthorizedRequest) OIDCConfig(com.okta.oidc.OIDCConfig) EncryptionManagerStub(com.okta.oidc.util.EncryptionManagerStub) SyncWebAuthClient(com.okta.oidc.clients.web.SyncWebAuthClient) Test(org.junit.Test)

Example 3 with SyncWebAuthClient

use of com.okta.oidc.clients.web.SyncWebAuthClient in project okta-oidc-android by okta.

the class OktaTest method testSyncWebBuilder.

@Test
public void testSyncWebBuilder() {
    Okta.SyncWebAuthBuilder builder = mock(Okta.SyncWebAuthBuilder.class);
    SyncWebAuthClient otherClient = new Okta.SyncWebAuthBuilder().withConfig(mConfig).withStorage(mStorage).withContext(mContext).withOktaHttpClient(mHttpClient).withTabColor(tabColor).supportedBrowsers(supportBrowsers).withEncryptionManager(mEncryptionManager).create();
    when(builder.create()).thenReturn(otherClient);
    builder.withConfig(mConfig);
    verify(builder).withConfig(mConfig);
    builder.withStorage(mStorage);
    verify(builder).withStorage(mStorage);
    builder.withOktaHttpClient(mHttpClient);
    verify(builder).withOktaHttpClient(mHttpClient);
    builder.withContext(mContext);
    verify(builder).withContext(mContext);
    builder.withTabColor(tabColor);
    verify(builder).withTabColor(tabColor);
    builder.supportedBrowsers(supportBrowsers);
    verify(builder).supportedBrowsers(supportBrowsers);
    builder.withEncryptionManager(mEncryptionManager);
    verify(builder).withEncryptionManager(mEncryptionManager);
    Object client = builder.create();
    verify(builder).create();
    assertEquals(otherClient, client);
}
Also used : SyncWebAuthClient(com.okta.oidc.clients.web.SyncWebAuthClient) Test(org.junit.Test)

Aggregations

SyncWebAuthClient (com.okta.oidc.clients.web.SyncWebAuthClient)3 SharedPreferenceStorage (com.okta.oidc.storage.SharedPreferenceStorage)2 EncryptionManagerStub (com.okta.oidc.util.EncryptionManagerStub)2 Test (org.junit.Test)2 Gson (com.google.gson.Gson)1 OIDCConfig (com.okta.oidc.OIDCConfig)1 AuthorizedRequest (com.okta.oidc.net.request.AuthorizedRequest)1 OktaStorage (com.okta.oidc.storage.OktaStorage)1 HttpClientFactory (com.okta.oidc.util.HttpClientFactory)1 MockEndPoint (com.okta.oidc.util.MockEndPoint)1 Before (org.junit.Before)1