001/*
002 * Copyright 2015 The AppAuth for Android Authors. All Rights Reserved.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005 * in compliance with the License. You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software distributed under the
010 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
011 * express or implied. See the License for the specific language governing permissions and
012 * limitations under the License.
013 */
014
015package net.openid.appauth;
016
017import android.os.Bundle;
018import androidx.appcompat.app.AppCompatActivity;
019
020/**
021 * Activity that receives the redirect Uri sent by the OpenID endpoint. It forwards the data
022 * received as part of this redirect to {@link AuthorizationManagementActivity}, which
023 * destroys the browser tab before returning the result to the completion
024 * {@link android.app.PendingIntent}
025 * provided to {@link AuthorizationService#performAuthorizationRequest}.
026 *
027 * App developers using this library must override the `appAuthRedirectScheme`
028 * property in their `build.gradle` to specify the custom scheme that will be used for
029 * the OAuth2 redirect. If custom scheme redirect cannot be used with the identity provider
030 * you are integrating with, then a custom intent filter should be defined in your
031 * application manifest instead. For example, to handle
032 * `https://www.example.com/oauth2redirect`:
033 *
034 * ```xml
035 * <intent-filter>
036 *   <action android:name="android.intent.action.VIEW"/>
037 *   <category android:name="android.intent.category.DEFAULT"/>
038 *   <category android:name="android.intent.category.BROWSABLE"/>
039 *   <data android:scheme="https"
040 *          android:host="www.example.com"
041 *          android:path="/oauth2redirect" />
042 * </intent-filter>
043 * ```
044 */
045public class RedirectUriReceiverActivity extends AppCompatActivity {
046
047    @Override
048    public void onCreate(Bundle savedInstanceBundle) {
049        super.onCreate(savedInstanceBundle);
050
051        // while this does not appear to be achieving much, handling the redirect in this way
052        // ensures that we can remove the browser tab from the back stack. See the documentation
053        // on AuthorizationManagementActivity for more details.
054        startActivity(AuthorizationManagementActivity.createResponseHandlingIntent(
055                this, getIntent().getData()));
056        finish();
057    }
058
059}