Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ jobs:

- name: Generate and submit dependency graph
uses: gradle/actions/dependency-submission@v3
if: github.event.pull_request.head.repo.full_name == github.repository
env:
# Do not include test and plugin dependencies in the report
DEPENDENCY_GRAPH_INCLUDE_CONFIGURATIONS: '.*(annotationProcessor|compileClasspath|productionRuntimeClasspath|runtimeClasspath).*'
Expand Down
119 changes: 87 additions & 32 deletions app/src/main/java/com/strivacity/demoapp/LoginFragment.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
package com.strivacity.demoapp;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.Navigation;

import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import com.strivacity.android.sdk.AuthFlowException;
import com.strivacity.android.sdk.FlowResponseCallback;

import java.util.Collections;
import java.util.Map;
import java.util.Objects;

public class LoginFragment extends Fragment {

Expand All @@ -38,11 +46,43 @@ public void onViewCreated(
) {
super.onViewCreated(view, savedInstanceState);

final Context context = view.getContext();
final Uri docsPage = Uri.parse(
getString(R.string.docs_url_custom_audiences)
);
final Intent openActionsDocs = new Intent(Intent.ACTION_VIEW, docsPage);

TextInputLayout textInputLayout = view.findViewById(
R.id.text_input_layout_audiences
);
textInputLayout.setEndIconOnClickListener(v -> {
try {
context.startActivity(openActionsDocs);
} catch (IllegalArgumentException ex) {
Log.e(
"FirstFragment",
"Could not open Docs page for custom audiences",
ex
);
Toast
.makeText(
context,
R.string.toast_error_failed_open_intent,
Toast.LENGTH_SHORT
)
.show();
}
});

TextView errorText = view.findViewById(R.id.errortext);
if (savedInstanceState != null) {
errorText.setText(savedInstanceState.getString("EXTRA_ERROR_TEXT"));
}

TextInputEditText audiencesInput = view.findViewById(
R.id.text_input_audiences
);

SharedViewModel viewModel = new ViewModelProvider(requireActivity())
.get(SharedViewModel.class);
viewModel
Expand All @@ -67,39 +107,54 @@ public void onViewCreated(

view
.findViewById(R.id.startFlow)
.setOnClickListener(v ->
authProvider.startFlow(
requireContext(),
new FlowResponseCallback() {
@Override
public void success(
@Nullable String accessToken,
@Nullable Map<String, Object> claims
) {
Log.d(TAG, "start flow success");
Navigation
.findNavController(
requireActivity(),
R.id.nav_host_fragment
)
.navigate(
R.id.action_loginFragment_to_mainFragment
.setOnClickListener(v -> {
String audiencesInputText = Objects
.requireNonNull(audiencesInput.getText())
.toString();
String[] audiences = audiencesInputText.isBlank()
? null
: audiencesInputText.split("\\s+");

authProvider
.withAudiences(audiences)
.startFlow(
requireContext(),
new FlowResponseCallback() {
@Override
public void success(
@Nullable String accessToken,
@Nullable Map<String, Object> claims
) {
Log.d(
TAG,
"start flow success"
);
}

@Override
public void failure(
@NonNull AuthFlowException exception
) {
Log.d(TAG, "start flow failure");
errorText.setText(
exception.toString()
);
}
},
Map.of("testKey", "testValue")
)
);
Navigation
.findNavController(
requireActivity(),
R.id.nav_host_fragment
)
.navigate(
R.id.action_loginFragment_to_mainFragment
);
}

@Override
public void failure(
@NonNull AuthFlowException exception
) {
Log.d(
TAG,
"start flow failure"
);
errorText.setText(
exception.toString()
);
}
},
Collections.emptyMap()
);
});
})
);
}
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/drawable/ic_help.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp" android:height="24dp" android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#000000"
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,19h-2v-2h2v2zM15.07,11.25l-0.9,0.92C13.45,12.9 13,13.5 13,15h-2v-0.5c0,-1.1 0.45,-2.1 1.17,-2.83l1.24,-1.26c0.37,-0.36 0.59,-0.86 0.59,-1.41 0,-1.1 -0.9,-2 -2,-2s-2,0.9 -2,2L8,9c0,-2.21 1.79,-4 4,-4s4,1.79 4,4c0,0.88 -0.36,1.68 -0.93,2.25z" />
</vector>
17 changes: 16 additions & 1 deletion app/src/main/res/layout/fragment_login.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" android:orientation="vertical"
android:padding="10dp" tools:context=".LoginFragment">

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_layout_audiences"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="@string/text_input_hint_custom_audiences"
app:endIconContentDescription="Info"
app:endIconDrawable="@drawable/ic_help" app:endIconMode="custom"
app:helperText="Audiences separated by space">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/text_input_audiences"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>

<Button android:id="@+id/startFlow"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_gravity="center"
android:text="@string/start_login_flow" />
android:layout_marginTop="8dp" android:text="@string/start_login_flow" />

<TextView android:id="@+id/errortext"
android:layout_width="wrap_content"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
<string name="logout">Logout</string>
<string name="get_last_claims">Get last claims</string>
<string name="get_access_token">Get Access Token and additional params</string>
<string name="docs_url_custom_audiences">https://docs.strivacity.com/docs/oauth2-oidc-properties-setup#allowed-custom-audiences</string>
<string name="toast_error_failed_open_intent">Could not open Docs page for custom audiences</string>
<string name="text_input_hint_custom_audiences">Custom Audiences</string>
</resources>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
id 'com.android.application' version '8.6.1' apply false
id 'com.android.library' version '8.6.1' apply false

id 'com.diffplug.spotless' version '6.18.0'
id 'com.diffplug.spotless' version '8.1.0'
}

spotless {
Expand Down
Loading
Loading