Amber Web Authorization not available in qtCreator

Hello,
I’m using qtcreator (4.15.2, Sailfish SDK 3.9.6) on a Windows10 laptop, and tried to use Amber Web Authorization. I copied the examples (main.cpp, amperwebauthcppemaple.pro) given on Amber Web Authorization - Sailfish OS and tried to follow the instructions on Amber Web Authorization - Sailfish OS. But qtcreator complained

main.cpp:9:11: error: ‘oauth2.h’ file not found
\oauth2\main.cpp:9: error: oauth2.h: No such file or directory
…/…/oauth2/main.cpp:9:11: fatal error: oauth2.h: No such file or directory
#include <oauth2.h>
^~~~~~~~~~

and

main.cpp:10:11: error: ‘redirectlistener.h’ file not found

And as a result, a number of unknown types:

\oauth2\main.cpp:40: error: use of undeclared identifier ‘OAuth2’

So, how to add oauth2.h and redirectlistener.h?

1 Like

Sounds like some dev package is missing from the sdk env?

If so, is there something I can do?

I tried reloading and reinstalling sdk, but no help.

[Edit]
Help->System Information gives

Library info:
PrefixPath: C:\SailfishOS\bin
DocumentationPath: C:\SailfishOS\bin\doc
HeadersPath: C:\SailfishOS\bin\include
LibrariesPath: C:\SailfishOS\bin
LibraryExecutablesPath: C:\SailfishOS\bin\bin
BinariesPath: C:\SailfishOS\bin
PluginsPath: C:\SailfishOS\bin\plugins
ImportsPath: C:\SailfishOS\bin\imports
Qml2ImportsPath: C:\SailfishOS\bin\qml
ArchDataPath: C:\SailfishOS\bin
DataPath: C:\SailfishOS\bin
TranslationsPath: C:\SailfishOS\bin\translations
ExamplesPath: C:\SailfishOS\bin\examples
TestsPath: C:\SailfishOS\bin\tests
SettingsPath:

but there’s only clang, lib, plugins, qml -directories in C:\SailfishOS\bin.
[/Edit]

No. You need to install the dev package in the sdk env. Sfos qtcreator used to have a ui for this, im not sure nowadays tho if it can be done via command line only.
see here

for example.

ps: the 2pennies for google are always worth it!

I believe, to quote:

If you’re working with the IDE, you’ll also need to add the following lines to your spec file:

Requires:   amber-web-authorization
Requires:   libamberwebauthorization

If you’re doing this direct from the command line on your phone, you’ll have to install these yourself manually, like this.

devel-su pkcon install amber-web-authorization libamberwebauthorization

For installing packages in the SDK use zypper. I usually set the target first. Example


#export TARGET=SailfishOS-4.4.0.58-i486 
#export TARGET=SailfishOS-4.4.0.58-armv7hl 
export TARGET=SailfishOS-4.4.0.58-aarch64 


sb2 -t $TARGET -m sdk-install -R zypper in contactsd-devel nemo-qml-plugin-contacts-qt5-devel kcalcore-qt5-devel
1 Like

Installing directly into the SDK as @deloptes describes will work, but I think it’s better to use the Requires method described by @poetaster where you can, since this will then work seamlessly with the snapshots functionality of sfdk as well (whereas installing directly into the target is liable to mess this up a little).

2 Likes

Thanks for the tips, but the problem remains. I tried it also with a fresh intall in freshly installed Ubuntu 22.04, but similar results.

The editor does not recognize OAuth2- or Redirectlistener-classes, so there’s no autocompletion of function names etc. So the editor is showing error

\oauth2\main.cpp:40: error: use of undeclared identifier ‘OAuth2’

already before I press the build-button.

I assume that adding Requires in the spec-file could solve the problems in compiling the code, but not the problems with the editor.

I did not try sb2, because I don’t know where to get it. I found the source code in git, but don’t want to start compiling it, if it does what Requires field does.

In qtCreator Tools->Options->SailfishOs->Manage build targets opened a dialog where I could add amber-web-authorization and libamberwebauthorization in targets SailfishOS-4.4.0.58-i486, -armv7hl, and -aarch64, but doing that did not help either. I assume this does the same as sb2-tip does.

Here’s my spec file:

# 
# Do NOT Edit the Auto-generated Part!
# Generated by: spectacle version 0.32
# 

Name:       oauth2

# >> macros
# << macros

%{!?qtc_qmake:%define qtc_qmake %qmake}
%{!?qtc_qmake5:%define qtc_qmake5 %qmake5}
%{!?qtc_make:%define qtc_make make}
%{?qtc_builddir:%define _builddir %qtc_builddir}
Summary:    oauthentication component
Version:    1.0
Release:    1
Group:      Qt/Qt
License:    LICENSE
URL:        http://example.org/
Source0:    %{name}-%{version}.tar.bz2
Source100:  oauth2.yaml
Requires:   sailfishsilica-qt5 >= 0.10.9
Requires:   qml(org.freedesktop.contextkit)
Requires:   amber-web-authorization
Requires:   libamberwebauthorization
BuildRequires:  pkgconfig(sailfishapp) >= 1.0.2
BuildRequires:  pkgconfig(Qt5Core)
BuildRequires:  pkgconfig(Qt5Qml)
BuildRequires:  pkgconfig(Qt5Quick)
BuildRequires:  desktop-file-utils

%description
oauthentication component


%prep
%setup -q -n %{name}-%{version}

# >> setup
# << setup

%build
# >> build pre
# << build pre

%qtc_qmake5 

%qtc_make %{?_smp_mflags}

# >> build post
# << build post

%install
rm -rf %{buildroot}
# >> install pre
# << install pre
%qmake5_install

# >> install post
# << install post

desktop-file-install --delete-original       \
  --dir %{buildroot}%{_datadir}/applications             \
   %{buildroot}%{_datadir}/applications/*.desktop

%files
%defattr(-,root,root,-)
%{_bindir}
%{_datadir}/%{name}
%{_datadir}/applications/%{name}.desktop
%{_datadir}/icons/hicolor/*/apps/%{name}.png
%{_datadir}/%{name}/translations
# >> files
# << files

and here’s the output

$ sfdk build ../amberwebauthcppexample/
NOTICE: Using the 'SailfishOS-4.4.0.58-i486.default' snapshot of the build target
NOTICE: Files with CRLF line endings found. Consult the Sailfish SDK FAQ to learn why to avoid that and how.
Loading repository data...
Reading installed packages...
'pkgconfig(sailfishapp) >= 1.0.2' not found in package names. Trying capabilities.
'libsailfishapp-devel' providing 'pkgconfig(sailfishapp) >= 1.0.2' is already installed.
'pkgconfig(Qt5Core)' not found in package names. Trying capabilities.
'qt5-qtcore-devel' providing 'pkgconfig(Qt5Core)' is already installed.
'pkgconfig(Qt5Qml)' not found in package names. Trying capabilities.
'qt5-qtdeclarative-devel' providing 'pkgconfig(Qt5Qml)' is already installed.
'pkgconfig(Qt5Quick)' not found in package names. Trying capabilities.
'qt5-qtdeclarative-qtquick-devel' providing 'pkgconfig(Qt5Quick)' is already installed.
'desktop-file-utils' is already installed.
No update candidate for 'desktop-file-utils-0.26+git3-1.7.1.jolla.i486'. The highest available version is already installed.
Resolving package dependencies...

Nothing to do.
Building target platforms: i486-meego-linux-gnu
Building for target i486-meego-linux-gnu
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.yU8PzL
+ umask 022
+ cd /home/pekka/koodi/testit/builds
+ LANG=C
+ export LANG
+ unset DISPLAY
+ CFLAGS='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -m32 -msse -msse2 -march=i686 -mfpmath=sse -mtune=generic -fno-omit-frame-pointer -fasynchronous-unwind-tables'
+ export CFLAGS
+ CXXFLAGS='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -m32 -msse -msse2 -march=i686 -mfpmath=sse -mtune=generic -fno-omit-frame-pointer -fasynchronous-unwind-tables'
+ export CXXFLAGS
+ FFLAGS='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -m32 -msse -msse2 -march=i686 -mfpmath=sse -mtune=generic -fno-omit-frame-pointer -fasynchronous-unwind-tables -I/usr/lib/gfortran/modules'
+ export FFLAGS
+ LD_AS_NEEDED=1
+ export LD_AS_NEEDED
+ export QT_SELECT=5
+ QT_SELECT=5
+ qmake -qt=5 -makefile 'QMAKE_CFLAGS_RELEASE=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -m32 -msse -msse2 -march=i686 -mfpmath=sse -mtune=generic -fno-omit-frame-pointer -fasynchronous-unwind-tables' 'QMAKE_CFLAGS_DEBUG=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -m32 -msse -msse2 -march=i686 -mfpmath=sse -mtune=generic -fno-omit-frame-pointer -fasynchronous-unwind-tables' 'QMAKE_CXXFLAGS_RELEASE=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -m32 -msse -msse2 -march=i686 -mfpmath=sse -mtune=generic -fno-omit-frame-pointer -fasynchronous-unwind-tables' 'QMAKE_CXXFLAGS_DEBUG=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -m32 -msse -msse2 -march=i686 -mfpmath=sse -mtune=generic -fno-omit-frame-pointer -fasynchronous-unwind-tables' QMAKE_STRIP=: PREFIX=/usr LIBDIR=/usr/lib
/home/mersdk/.mb2/wrappers/testit/builds/qmake: Executing real qmake:
+ /usr/bin/qmake -qt=5 -makefile 'QMAKE_CFLAGS_RELEASE=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -m32 -msse -msse2 -march=i686 -mfpmath=sse -mtune=generic -fno-omit-frame-pointer -fasynchronous-unwind-tables' 'QMAKE_CFLAGS_DEBUG=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -m32 -msse -msse2 -march=i686 -mfpmath=sse -mtune=generic -fno-omit-frame-pointer -fasynchronous-unwind-tables' 'QMAKE_CXXFLAGS_RELEASE=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -m32 -msse -msse2 -march=i686 -mfpmath=sse -mtune=generic -fno-omit-frame-pointer -fasynchronous-unwind-tables' 'QMAKE_CXXFLAGS_DEBUG=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -m32 -msse -msse2 -march=i686 -mfpmath=sse -mtune=generic -fno-omit-frame-pointer -fasynchronous-unwind-tables' QMAKE_STRIP=: PREFIX=/usr LIBDIR=/usr/lib /home/pekka/koodi/testit/amberwebauthcppexample
+ make -j4
g++ -c -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -m32 -msse -msse2 -march=i686 -mfpmath=sse -mtune=generic -fno-omit-frame-pointer -fasynchronous-unwind-tables -D_REENTRANT -Wall -W -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I../amberwebauthcppexample -I. -I../amberwebauthcppexample -I../../lib -isystem /home/pekka/koodi/SailfishOS/mersdk/targets/SailfishOS-4.4.0.58-i486.default/usr/include/qt5 -isystem /home/pekka/koodi/SailfishOS/mersdk/targets/SailfishOS-4.4.0.58-i486.default/usr/include/qt5/QtGui -isystem /home/pekka/koodi/SailfishOS/mersdk/targets/SailfishOS-4.4.0.58-i486.default/usr/include/qt5/QtNetwork -isystem /home/pekka/koodi/SailfishOS/mersdk/targets/SailfishOS-4.4.0.58-i486.default/usr/include/qt5/QtCore -I. -I/usr/share/qt5/mkspecs/linux-g++ -o main.o ../amberwebauthcppexample/main.cpp
../amberwebauthcppexample/main.cpp:9:11: fatal error: oauth2.h: No such file or directory
  #include <oauth2.h>
           ^~~~~~~~~~
compilation terminated.
make: *** [Makefile:401: main.o] Error 1
error: Bad exit status from /var/tmp/rpm-tmp.yU8PzL (%build)


RPM build errors:
    Bad exit status from /var/tmp/rpm-tmp.yU8PzL (%build)

Back to the basics. Perhaps repeating things will help.

I reinstalled Sailfish sdk 3.9.6 in my windows laptop.

When I open main.cpp of the amberwebauthcppexample in qtCreator, the editor complains about not finding the header files oauth2.h and redirectlistener.h.


As a result there are type errors also:

Should I do something to make the editor recognize types OAuth2 and RedirectListener?

In the pro-file I have

CONFIG += link_pkgconfig
PKGCONFIG += amberwebauthorization

If I try sb2 -t SailfishOS-4.4.0.58-aarch64 -m sdk-install -R zypper in amber-web-authorization libamberwebauthorization in the command prompt, I get error 'sb2' is not recognized.

In the yaml-file I have:

PkgConfigBR:
  - sailfishapp >= 1.0.2
  - Qt5Core
  - Qt5Qml
  - Qt5Quick

Requires:
  - sailfishsilica-qt5 >= 0.10.9
  - qml(org.freedesktop.contextkit)
  - amber-web-authorization
  - libamberwebauthorization

Compiling gives errors - oauth2.h and redirectlistener.h not found.

If I try amberwebauthqmlexample the editor complans about line import Amber.Web.Authorization 1.0 - QML module not found. And building the project ends in errors

RPM build errors:
Error on file “/home/deploy/installroot/usr/share/applications/*.desktop”: No such file or directory
error: Bad exit status from /var/tmp/rpm-tmp.y3VmMJ (%install)

And the app window does not open in the sfos device running in the virtual box.

I’m sorry this has been giving you trouble @hsjpekka and thanks for sharing clear details of how you have things configured; that helps a lot. It looks like you’re missing amberwebauthorization from the PkgConfigBR section of your yaml file; see the last line here:

PkgConfigBR:
  - sailfishapp >= 1.0.2
  - Qt5Core
  - Qt5Qml
  - Qt5Quick
  - amberwebauthorization

Hopefully adding this will allow your app to build correctly.

It might be helpful to have a bit of explanation in case you or others experience similar issues in the future.

The Requires section of the yaml file deals only with packages that are needed for your app to run on the device (i.e. it’ll install those packages on your phone if they’re not already there when you install your app). However, it doesn’t help with build-time dependencies that are installed into your SDK when your app is built.

For build-time dependencies, you need to add things to either the PkgConfigBR or PkgBR sections. The line you have to add isn’t always the same in both cases and the actual way to know what to add can be a bit arcane. Usually the best way to find out is from the documentation.

In this case, this requirement is stated in the documentation like this:

To use the C++ API, the client application should use the “amberwebauthorization.pc” pkgconfig file.

Admittedly it seems to me that it could be stated a bit more clearly.

So, just to walk through what I did to check this:

  1. Created a new Sailfish app using the Sailfish IDE.
  2. Copied over the contents of the example amberwebauthcppexample/main.cpp into the main.cpp file of my new project.
  3. At this point I attempted to build the project using the “Build project for manual deployment” option in the IDE (Ctrl-B). This generated the error “Project ERROR: amberwebauthorization development package not found”.
  4. To fix this I added the amberwebauthorization entry to the PkgConfigBR section of my project’s yaml file.
  5. I then re-ran qmake by selecting “Build > Run qmake” in the IDE. This step is essential, otherwise the package won’t get installed. During this step I was able to see the package being installed in the console output.
  6. Now building the project (Ctrl-B) completes without error.

As an aside, if you’re just using Amber WebAuth in your QML then you don’t need to install the build-time packages, they’re only needed if you’re going to compile and link against them (e.g. for use with C++ code).

Just finally, this didn’t fix the errors appearing in the main.cpp file in the IDE. These shouldn’t affect the build, but it would be helpful if the syntax highlighting picked them up, so I’ve created an internal issue in case there’s a way to fix it.

3 Likes

I’ve proposed a PR to the documentation to try to make these build requirements clearer:

@hsjpekka: It would be good to know your (or indeed others) thoughts on whether this change to the docs would have helped you, or if there’s some better way to explain what’s needed.

4 Likes

Sorry for going a bit off-topic, but I just couldn’t resists:

First of all, sb2 is a low level tool. It’s quite rare that one should be using it directly. For application developers, sfdk is quite often the tool they should be using directly. In this specific case, the command to use would be sfdk tools package-install SailfishOS-4.4.0.58-aarch64 amber-web-authorization libamberwebauthorization. But of course, instead of doing even that, you should be adding the BuildRequires, like @flypig instructed.

3 Likes

Vige, come on, sfdk is rather modern :slight_smile:
But I listen to your wisdom and will translate all my notes to sfdk

Thanks.

Simple yes/no-answers to the following questions would be enough to make me happy:

If I have understood correctly, the webauthorization uses the default browser for authentication. And the sailfish os emulator in the virtual box in my laptop does not come with a browser, so I should install the app in my phone to try if it works?

Is it enough to install some browser in the emulator as the default one to be able to use the webauthorization, or does it require more?