Auth0のOpenID Connectによる認証を組み込むアプリケーションとして、以下のLiveLabsを実施して作成したアプリケーションを使用します。
- Build a Recipe Web App with Oracle Backend for Firebase
- Build a Recipe iOS App with Oracle Backend for Firebase
- Build a Recipe Android App with Oracle Backend for Firebase
Auth0のOpenID Connectプロバイダを構成する
プロバイダをEnableに切り替えます。Enableにすると、リダイレクトURIが表示されます。なぜかCopy URIボタンが効かない(サイトをHTTPで構成しているからかもしれません)ため、表示されているリダイレクトURIを選択して、クリップボードにコピーします。
Client IdおよびClient Secretは、Auth0にアプリケーションを作成することにより得られる値なので現時点では不明です。キャンセルをクリックし、ドロワーを閉じます。
Oracle Backend for Firebaseのコンソールに戻り、Authenticationを開きます。
Add new providerのOpenID Connectを実行します。
作成するプロバイダの名前(Name)はauth0とします。ここで設定した名前auth0に接頭辞としてoidc_が付けられたoidc_auth0が、作成されるプロバイダの名前になります。Enableをオフにすれば実質的には同じなのですが、作成したプロバイダを削除する方法が無い(見つけられなかった)、また、名前の変更もできないため、名前は注意して決めることをお勧めします。
curl -s https://[ドメイン]/.well-known/openid-configuration | jq -r .issuer
~ % curl -s https://[ドメイン]/.well-known/openid-configuration | jq -r .issuer
https://[ドメイン]/
~ %
curl -s https://[ドメイン]/.well-known/openid-configuration | jq -r .authorization_endpoint
~ % curl -s https://[ドメイン]/.well-known/openid-configuration | jq -r .authorization_endpoint
https://[ドメイン]/authorize
~ %
Web/JavaScriptアプリケーションを認証する
import {
GoogleAuthProvider,
OAuthProvider,
signInWithPopup,
createUserWithEmailAndPassword,
getAuth,
onAuthStateChanged,
signInWithEmailAndPassword,
signOut
} from "fusabase/auth";
el.signInWithOIDCButton.addEventListener("click", () => {
runAction("Signed in with OIDC.", async () => {
// ── Sign in with OIDC ─────────
const provider = new OAuthProvider("oidc_auth0");
const userCredential = await signInWithPopup(auth, provider);
// console.log(userCredential);
});
});iOS/Swiftアプリケーションを認証する
/// Sign in with OIDC
func signInWithOIDC() async throws {
isLoading = true
errorMessage = nil
defer { isLoading = false }
do {
_ = try await FusabaseAuth.auth().signIn(with: OAuthProvider(providerID: "oidc_auth0"))
} catch {
errorMessage = error.localizedDescription
throw error
}
} // MARK: - Actions
private func signInWithOIDC() {
Task {
do {
try await authService.signInWithOIDC()
} catch {
// AuthService surfaces the message via `errorMessage`; nothing else to do.
}
}
} // Sign In With OIDC
Button(action: signInWithOIDC) {
HStack {
if authService.isLoading {
ProgressView()
.controlSize(.small)
.padding(.trailing, 4)
}
Text("Sign In with OIDC")
.fontWeight(.semibold)
.frame(maxWidth: .infinity)
}
}
.buttonStyle(.borderedProminent)
.controlSize(.large)
.disabled(authService.isLoading)Android/Javaアプリケーションを認証する
/**
* Sign in with OIDC.
*/
public void signInWithOIDC(Activity activity) {
isLoading.setValue(true);
errorMessage.setValue(null);
OAuthProvider.Builder builder = OAuthProvider.newBuilder("oidc_auth0");
OAuthProvider provider = builder.build();
auth.startActivityForSignInWithProvider(activity, provider)
.addOnSuccessListener(result -> isLoading.postValue(false))
.addOnFailureListener(error -> {
isLoading.postValue(false);
errorMessage.postValue(error.getMessage());
});
}
public void resumePendingSocialLogin() {
Task<AuthResult> pending = auth.getPendingAuthResult();
if (pending == null) {
isLoading.postValue(false);
return;
}
pending.addOnSuccessListener(result -> isLoading.postValue(false))
.addOnFailureListener(error -> {
isLoading.postValue(false);
errorMessage.postValue(error.getMessage());
});
}/* Sign in with Google */
import android.app.Activity;
import com.oracle.mobile.fusabase.auth.GoogleAuthProvider;
import com.oracle.mobile.fusabase.auth.OAuthProvider;
import com.oracle.mobile.fusabase.task.Task;
import com.oracle.mobile.fusabase.auth.AuthResult;<string name="auth_button_oidc">Sign in with OIDC</string>
<com.google.android.material.button.MaterialButton
android:id="@+id/oidcButton"
style="@style/Widget.Material3.Button.OutlinedButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_sm"
android:text="@string/auth_button_oidc" /> binding.oidcButton.setOnClickListener(v -> {
binding.errorText.setVisibility(View.GONE);
App.get().auth().signInWithOIDC(requireActivity());
});binding.oidcButton.setEnabled(!active);
@Override
public void onResume() {
super.onResume();
App.get().auth().resumePendingSocialLogin();
}baasmobile581fb7467326f5b9e063020012ac0157
<activity
android:name="com.oracle.mobile.fusabase.auth.SocialLoginActivity"
android:exported="true"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="baasmobile581fb7467326f5b9e063020012ac0157" />
</intent-filter>
</activity>~/Library/Android/sdk/platform-tools/adb reverse --list
% ~/Library/Android/sdk/platform-tools/adb reverse tcp:8181 tcp:8181
% ~/Library/Android/sdk/platform-tools/adb reverse --list
host-10 tcp:8181 tcp:8181
%





































































