Skip to content

Commit f56d133

Browse files
Merge pull request #192 from frontegg/FR-22559-access-token-retrieval-examples
FR-22559 Added examples for access token retrieval below "sensitive action button" after login
2 parents 2e00b64 + f048c73 commit f56d133

File tree

12 files changed

+129
-2
lines changed

12 files changed

+129
-2
lines changed

app/src/main/java/com/frontegg/demo/ui/home/HomeFragment.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,27 @@ class HomeFragment : Fragment() {
140140
}
141141
}
142142

143+
binding.receiveTokenButton.setOnClickListener {
144+
val token = requireContext().fronteggAuth.accessToken.value
145+
if (token.isNullOrEmpty()) {
146+
Toast.makeText(
147+
requireContext(),
148+
"Access token is not available yet",
149+
Toast.LENGTH_SHORT
150+
).show()
151+
} else {
152+
val clipboard =
153+
requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
154+
val clip = ClipData.newPlainText("Access Token", token)
155+
clipboard.setPrimaryClip(clip)
156+
Toast.makeText(
157+
requireContext(),
158+
"Access token was copied to clipboard",
159+
Toast.LENGTH_SHORT
160+
).show()
161+
}
162+
}
163+
143164
/**
144165
* Opens the Frontegg Android Kotlin documentation in the default browser.
145166
* This button is part of the footer and provides quick access to the official documentation.

app/src/main/java/com/frontegg/demo/ui/home/HomeViewModel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ class HomeViewModel(private val fronteggAuth: FronteggAuth) : ViewModel() {
3838

3939

4040
val user: LiveData<User?> = _user
41+
val accessToken: LiveData<String?> = _accessToken
4142
}

app/src/main/res/layout/fragment_home.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@
126126
android:layout_marginEnd="24dp"
127127
android:text="Sensitive action" />
128128

129+
<Button
130+
android:id="@+id/receive_token_button"
131+
style="@style/CustomButton"
132+
android:layout_width="match_parent"
133+
android:layout_height="wrap_content"
134+
android:layout_marginBottom="24dp"
135+
android:layout_marginStart="24dp"
136+
android:layout_marginEnd="24dp"
137+
android:text="Get access token" />
138+
129139

130140
</LinearLayout>
131141
</com.google.android.material.card.MaterialCardView>

applicationId/src/main/java/com/frontegg/demo/ui/home/HomeFragment.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,27 @@ class HomeFragment : Fragment() {
140140
}
141141
}
142142

143+
binding.receiveTokenButton.setOnClickListener {
144+
val token = requireContext().fronteggAuth.accessToken.value
145+
if (token.isNullOrEmpty()) {
146+
Toast.makeText(
147+
requireContext(),
148+
"Access token is not available yet",
149+
Toast.LENGTH_SHORT
150+
).show()
151+
} else {
152+
val clipboard =
153+
requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
154+
val clip = ClipData.newPlainText("Access Token", token)
155+
clipboard.setPrimaryClip(clip)
156+
Toast.makeText(
157+
requireContext(),
158+
"Access token was copied to clipboard",
159+
Toast.LENGTH_SHORT
160+
).show()
161+
}
162+
}
163+
143164
/**
144165
* Opens the Frontegg Android Kotlin documentation in the default browser.
145166
* This button is part of the footer and provides quick access to the official documentation.

applicationId/src/main/java/com/frontegg/demo/ui/home/HomeViewModel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ class HomeViewModel(
3939

4040

4141
val user: LiveData<User?> = _user
42+
val accessToken: LiveData<String?> = _accessToken
4243
}

applicationId/src/main/res/layout/fragment_home.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@
126126
android:layout_marginEnd="24dp"
127127
android:text="Sensitive action" />
128128

129+
<Button
130+
android:id="@+id/receive_token_button"
131+
style="@style/CustomButton"
132+
android:layout_width="match_parent"
133+
android:layout_height="wrap_content"
134+
android:layout_marginBottom="24dp"
135+
android:layout_marginStart="24dp"
136+
android:layout_marginEnd="24dp"
137+
android:text="Get access token" />
138+
129139

130140
</LinearLayout>
131141
</com.google.android.material.card.MaterialCardView>

embedded/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@
4141
<!-- Enable EmbeddedAuthActivity, disable HostedAuthActivity -->
4242
<activity
4343
android:name="com.frontegg.android.EmbeddedAuthActivity"
44-
android:enabled="true"
44+
android:enabled="false"
4545
tools:replace="android:enabled" />
4646
<activity
4747
android:name="com.frontegg.android.HostedAuthActivity"
48-
android:enabled="false"
48+
android:enabled="true"
4949
tools:replace="android:enabled" />
5050

5151

embedded/src/main/java/com/frontegg/demo/ui/home/HomeFragment.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,27 @@ class HomeFragment : Fragment() {
140140
}
141141
}
142142

143+
binding.receiveTokenButton.setOnClickListener {
144+
val token = requireContext().fronteggAuth.accessToken.value
145+
if (token.isNullOrEmpty()) {
146+
Toast.makeText(
147+
requireContext(),
148+
"Access token is not available yet",
149+
Toast.LENGTH_SHORT
150+
).show()
151+
} else {
152+
val clipboard =
153+
requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
154+
val clip = ClipData.newPlainText("Access Token", token)
155+
clipboard.setPrimaryClip(clip)
156+
Toast.makeText(
157+
requireContext(),
158+
"Access token was copied to clipboard",
159+
Toast.LENGTH_SHORT
160+
).show()
161+
}
162+
}
163+
143164
/**
144165
* Opens the Frontegg Android Kotlin documentation in the default browser.
145166
* This button is part of the footer and provides quick access to the official documentation.

embedded/src/main/res/layout/fragment_home.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@
126126
android:layout_marginEnd="24dp"
127127
android:text="Sensitive action" />
128128

129+
<Button
130+
android:id="@+id/receive_token_button"
131+
style="@style/CustomButton"
132+
android:layout_width="match_parent"
133+
android:layout_height="wrap_content"
134+
android:layout_marginBottom="24dp"
135+
android:layout_marginStart="24dp"
136+
android:layout_marginEnd="24dp"
137+
android:text="Get access token" />
138+
129139

130140
</LinearLayout>
131141
</com.google.android.material.card.MaterialCardView>

multi-region/src/main/java/com/frontegg/demo/ui/home/HomeFragment.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,27 @@ class HomeFragment : Fragment() {
141141
}
142142
}
143143

144+
binding.receiveTokenButton.setOnClickListener {
145+
val token = requireContext().fronteggAuth.accessToken.value
146+
if (token.isNullOrEmpty()) {
147+
Toast.makeText(
148+
requireContext(),
149+
"Access token is not available yet",
150+
Toast.LENGTH_SHORT
151+
).show()
152+
} else {
153+
val clipboard =
154+
requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
155+
val clip = ClipData.newPlainText("Access Token", token)
156+
clipboard.setPrimaryClip(clip)
157+
Toast.makeText(
158+
requireContext(),
159+
"Access token was copied to clipboard",
160+
Toast.LENGTH_SHORT
161+
).show()
162+
}
163+
}
164+
144165
/**
145166
* Opens the Frontegg Android Kotlin documentation in the default browser.
146167
* This button is part of the footer and provides quick access to the official documentation.

0 commit comments

Comments
 (0)