Authenticate with OneDrive SDK in Xamarin Android App -
i use onedrive sdk in cross plattform app. on windows authentication works via onedriveclientextensions.getclientusingwebauthenticationbroker.
now i'm trying login on android. tried this:
onedriveclient = onedriveclient.getmicrosoftaccountclient( appid: msa_client_id, returnurl: return_url, scopes: scopes, clientsecret: msa_client_secret); await onedriveclient.authenticateasync(); but error no valid token received. have implement own authenticationprovider inhereting webauthenticationbrokerauthenticationprovider shows browser oauth? or way go here?
i solved using xamarin auth component. heres code calls webview login:
private const string return_url = @"https://login.live.com/oauth20_desktop.srf"; private void showwebview() { var auth = new oauth2authenticator( clientid: msa_client_id, scope: string.join(",", scopes), authorizeurl: new uri(getauthorizeurl()), redirecturl: new uri(return_url)); auth.completed += (sender, eventargs) => { if (eventargs.isauthenticated) { //do } }; var intent = auth.getui(application.context); intent.setflags(activityflags.newtask); application.context.startactivity(intent); } private string getauthorizeurl() { var requesturistringbuilder = new stringbuilder(); requesturistringbuilder.append("https://login.live.com/oauth20_authorize.srf"); requesturistringbuilder.appendformat("?{0}={1}", constants.authentication.redirecturikeyname, return_url); requesturistringbuilder.appendformat("&{0}={1}", constants.authentication.clientidkeyname, msa_client_id); requesturistringbuilder.appendformat("&{0}={1}", constants.authentication.scopekeyname, string.join("%20", scopes)); requesturistringbuilder.appendformat("&{0}={1}", constants.authentication.responsetypekeyname, constants.authentication.tokenresponsetypevaluename); return requesturistringbuilder.tostring(); }
Comments
Post a Comment